Fine-tuning: AttributeError: Cannot find field 'gt_masks' in DataLoader with COCO format

See original GitHub issue

Unfortunately, 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: image

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hpanwar08commented, Feb 18, 2021

Glad you figured it out.

1reaction
mbuet2nercommented, Feb 18, 2021

After a lot of debugging I found that for a couple of files the segmentation was 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 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find field 'gt_masks' in the given Instances ... - GitHub
AttributeError : Cannot find field 'gt_masks' in the given Instances! #485 ... d2.data.datasets.coco]: Loaded 2700 images in COCO format from ...
Read more >
How to train Detectron2 with Custom COCO Datasets - DLology
This tutorial will help you get started with Detectron2 framework by training an instance segmentation model with your custom COCO datasets.
Read more >
How to work with object detection datasets in COCO format
A comprehensive guide to defining, loading, exploring, and evaluating object detection datasets in COCO format using FiftyOne.
Read more >
detectron2.data
Register a dataset in COCO's json annotation format for instance detection, instance segmentation and keypoint detection. (i.e., Type 1 and 2 in http:// ......
Read more >
attributeerror: 'maskrcnn' object has no attribute 'call' - You.com
AttributeError : 'list' object has no attribute 'resize'. I know the right fomat should be "Boxlist", but I don't know how to cause...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found