Dataloaders for object detection and instance segmentation.
Load the path and DataFrame
of a downloaded dataset and create a DataLoader
in one line.
from fastai_object_detection.datasets import CocoData
path,df = CocoData.get_path_df("ds-cats-dogs")
df.head(2)
dls = ObjectDetectionDataLoaders.from_df(df, valid_pct=0.1, bs=2,
item_tfms=[Resize(512, method='pad', pad_mode='zeros')],
batch_tfms=[Normalize.from_stats(*imagenet_stats)])
Now you can show a batch as usual.
b = dls.one_batch()
[type(t) for t in b]
dls.show_batch(b, figsize=(10,10))
If the column mask_path
exists in your DataFrame
, it creates a DataLoader
with segmentation masks. If the column is not present, the dataloader only returns bounding boxes and labels.
df_bb_only = df.drop(columns=["mask_path"])
df_bb_only.head(2)
dls = ObjectDetectionDataLoaders.from_df(df_bb_only, valid_pct=0.1, bs=2,
item_tfms=[Resize(512, method='pad', pad_mode='zeros')],
batch_tfms=[Normalize.from_stats(*imagenet_stats)])
b = dls.one_batch()
[type(t) for t in b]
dls.show_batch(b, figsize=(10,10))