<jupyter_start><jupyter_text>Creating a new datasetIn this notebook we will have a look at creating a new dataset from a set of records. First we will take a look a the result of a training, make a selection based on the results and than train on the new dataset.<jupyter_code># Imports
import panel as pn

from icevision.all import *
import icedata
from icevision_dashboards.dashboards import *
from icevision_dashboards.data import *
pn.extension()<jupyter_output><empty_output><jupyter_text>Look at training results<jupyter_code>trainings_results = ObjectDetectionResultsDataset.load("test_data/fridge_example")<jupyter_output><empty_output><jupyter_text>If we take a look at the data below we can see that the model works better on images with only one annoation. Furthermore we can see, that the score distribution that the model is much more confident in some classes. (Here the reason is that the training was stopped before it could converge). Lets say we now want to create a subset and train a model on the subset, where the number of annotations equals 1 and we want to use the following classes Pug, Shiba Inu, Great Pyrenees ans Sphynx. We can use the `ObjectDetectionDatasetGenerator` dashboard to do this.<jupyter_code>trainings_resuls_overivew = ObjectDetectionResultOverview(trainings_results)
trainings_resuls_overivew.show_loss_tab()<jupyter_output><empty_output><jupyter_text>Create a subdataset<jupyter_code># load the data and class_map
path = icedata.fridge.load_data()
class_map = icedata.fridge.class_map()

# use the provided dataset parser
parser = icedata.fridge.parser(data_dir=path)
records = parser.parse(RandomSplitter([1]))[0]
# create a dataset the can be consumed by a dashboard
dash_ds = BboxRecordDataset(records, class_map=class_map)<jupyter_output><empty_output><jupyter_text>First select the ranges with the range silder than select the classes you want.<jupyter_code>dash_generator = ObjectDetectionDatasetGeneratorRange(dash_ds, width=1000, height=700)
dash_generator.show()
# load the created dataset
new_dataset = BboxRecordDataset("datasets/dataset.json")
# quick overview of the dataset
ObjectDetectionDatasetOverview(new_dataset, height=700, width=1000).show()
# split the records into a training and test dataset
train_records, valid_records = new_dataset.split_in_train_and_val(0.8)<jupyter_output><empty_output><jupyter_text>Train a model on the new DatasetNow that we have the new dataset we can train a model on the data.<jupyter_code># define transforms
train_tfms = tfms.A.Adapter(
    [*tfms.A.aug_tfms(size=384, presize=512), tfms.A.Normalize()]
)
valid_tfms = tfms.A.Adapter([*tfms.A.resize_and_pad(384), tfms.A.Normalize()])
# create the datasets and dataloaders
train_ds = Dataset(train_records, train_tfms)
valid_ds = Dataset(valid_records, valid_tfms)

train_dl = faster_rcnn.train_dl(train_ds, batch_size=8, num_workers=4, shuffle=True)
valid_dl = faster_rcnn.valid_dl(valid_ds, batch_size=8, num_workers=4, shuffle=False)
# create a model and train it for some epochs
model = faster_rcnn.model(num_classes=len(new_dataset.class_map))

learn = faster_rcnn.fastai.learner(dls=[train_dl, valid_dl], model=model)

learn.fine_tune(5, base_lr=1e-4)
samples_plus_losses, preds, losses_stats = faster_rcnn.interp.plot_top_losses(model=model, dataset=valid_ds, sort_by="loss_total", n_samples=1)
# create a dataset that can be consumed by the analysis dashboard
valid_result_ds = ObjectDetectionResultsDataset.init_from_preds_and_samples(preds, samples_plus_losses, class_map=class_map)
# create the dashboard
result_overview_dash = ObjectDetectionResultOverview(valid_result_ds)
# show the loss tab
result_overview_dash.show_loss_tab()
# show the ap tab
result_overview_dash.show_ap_tab()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07659687251523986, 'fraction_numerical': 0.00954147892923403, 'mean_word_length': 7.386666666666667, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '263161', 'license': 'Apache-2.0', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1194, 'n_words': 351, 'path': 'examples/creating_a_new_dataset.ipynb', 'repo_name': 'ZivotJeKrasny/icevision_dashboards', 'size': '3773'}