Fine-tuning: AttributeError: Cannot find field 'gt_masks' in DataLoader with COCO format
See original GitHub issueUnfortunately, I always run into an error when fine-tuning on my own dataset (in coco format). The detectron2 documentation on datasets was of no help either (maybe I overlooked something though).
After registering the data via register_coco_instances (as seen in train_net_dla.py) the following code
train data (train_data = DatasetCatalog.get("dla_train")
train data[0]
gives me:
{'file_name': 'cyber_train/public_imgs_sampled/file01.png',
'height': 1754,
'width': 1241,
'image_id': 0,
'annotations': [{'iscrowd': 0,
'bbox': [78, 600, 977, 33],
'category_id': 1,
'segmentation': [[83, 606, 83, 633, 1050, 633, 1050, 606]],
'bbox_mode': <BoxMode.XYWH_ABS: 1>}
...
which does look good to me telling from the COCO formatting style.
I can even visualize the data using Visualizer:
for d in random.sample(train_data, 1):
img = cv2.imread(d["file_name"])
visualizer = Visualizer(img[:, :, :], scale=0.5)
out = visualizer.draw_dataset_dict(d)
plt.imshow(out.get_image()[:,:,::-1])
which gives me the expected output:

Creating the trainer is also possible using trainer = DefaultTrainer(cfg) , but calling trainer.train() gives me a stack trace for the AttributeError: Cannot find field 'gt_masks' in the given Instances!' in DataLoader.
I am very confused about the error, because ‘segmentation’ is present in the train_data and the specified polygons are also valid telling from the output of Visualizer.
Anyway, thank you very much for your great work @hpanwar08 !
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Related StackOverflow Question
Glad you figured it out.
After a lot of debugging I found that for a couple of files the
segmentationwas missing somehow and therefore something went wrong during labeling.As a somewhat ugly workaround I just replaced the empty segmentation with their respective bounding box. Thanks for your help @hpanwar08 !