Classes to build datasets for object detection and instance segmentation
/home/user/jupyter/env/lib/python3.7/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0

class CocoData[source]

CocoData()

Creates dataset for object detection models by downloading images from coco dataset. Specify the name of the dataset and which categories it should contain. If data_path is None it creates a new folder in fastai's data path, like untar_data. By default only bounding boxes, optionally with masks and crowded objects.

CocoData.create[source]

CocoData.create(ds_name, cat_list, data_path=None, with_mask=False, max_images=1000, remove_crowded=True)

Creates a new coco dataset with categories defined in cat_list, optionally with or without masks. You can specify the path, where the dataset gets stored, by default it uses fastai's data path like untar_data

Create a new dataset for cats and dogs detection

path,df = CocoData.create("ds-cats-dogs", cat_list=["cat", "dog"], with_mask=True, max_images=100)
Creating folders.
Downloading annotation files...
loading annotations into memory...
Done (t=14.77s)
creating index...
index created!
Found 2 valid categories.
['cat', 'dog']
Starting download.
Downloading images of category cat
Downloading images of category dog
197 images downloaded.
Creating Dataframe...
100.00% [197/197 00:01<00:00]
path
Path('/home/user/.fastai/data/ds-cats-dogs')
df.head(5)
image_id image_path mask_path object_id x_min y_min x_max y_max class_name
0 237643 /home/user/.fastai/data/ds-cats-dogs/images/000000237643.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000237643_0.png 0 385.42 53.01 619.38 178.05 dog
1 157981 /home/user/.fastai/data/ds-cats-dogs/images/000000157981.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000157981_0.png 0 50.58 39.23 272.52 468.65 cat
2 157981 /home/user/.fastai/data/ds-cats-dogs/images/000000157981.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000157981_1.png 1 436.90 271.96 507.92 394.11 cat
3 237772 /home/user/.fastai/data/ds-cats-dogs/images/000000237772.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000237772_0.png 0 241.79 302.01 348.00 366.92 cat
4 122913 /home/user/.fastai/data/ds-cats-dogs/images/000000122913.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000122913_0.png 0 63.09 61.50 224.02 240.00 cat

CocoData.get_path_df[source]

CocoData.get_path_df(ds_name, data_path=None)

Get path and dataframe of downloaded coco dataset.

When you already downloaded a dataset, you can get the path and DataFrame by its name:

path,df = CocoData.get_path_df("ds-cats-dogs")
path
Path('/home/user/.fastai/data/ds-cats-dogs')
df.head(2)
image_id image_path mask_path object_id x_min y_min x_max y_max class_name
0 237643 /home/user/.fastai/data/ds-cats-dogs/images/000000237643.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000237643_0.png 0 385.42 53.01 619.38 178.05 dog
1 157981 /home/user/.fastai/data/ds-cats-dogs/images/000000157981.jpg /home/user/.fastai/data/ds-cats-dogs/masks/000000157981_0.png 0 50.58 39.23 272.52 468.65 cat

CocoData.ls[source]

CocoData.ls(data_path=None)

List all available datasets.

CocoData.remove[source]

CocoData.remove(ds_name, data_path=None)

Remove a downloaded coco dataset.

CocoData.show_examples[source]

CocoData.show_examples(ds_name, data_path=None, n=3)

Show examples of a downloaded coco dataset.

CocoData.show_examples("ds-cats-dogs", n=5)