open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.24k stars 9.41k forks source link

len() of a numpy.ndarray causes "len() of unsized object" error. #3602

Closed zeakey closed 1 year ago

zeakey commented 4 years ago

The process_polygons() function https://github.com/open-mmlab/mmdetection/blob/9596b9a4c916ae601f9a8a641c3a0ea47265abec/mmdet/datasets/pipelines/loading.py#L268-L271 uses the buitin function len() to a numpy.ndarray object, leading to a TypeError: len() of unsized object error.

This issue is related to #3599 where I tried to output polygon-style annotations to the FCNMaskHead.

ZwwWayne commented 4 years ago

This is because the polygon is a scalar or something that does not have __len__, you need to check the format of your annotations, especially the type of polygon.

zeakey commented 4 years ago

This is because the polygon is a scalar or something that does not have __len__, you need to check the format of your annotations, especially the type of polygon.

polygon seems to be RLE format annotation encoded as a np.ndarray:

QQ图片20200824170932

As mentioned in #3599 , I simply add poly2mask=False to dict(type='LoadAnnotations', with_bbox=True, with_mask=True, poly2mask=False) https://github.com/open-mmlab/mmdetection/blob/9596b9a4c916ae601f9a8a641c3a0ea47265abec/configs/_base_/datasets/cityscapes_instance.py#L7, and then start training by python tools/train.py configs/cityscapes/mask_rcnn_r50_fpn_1x_cityscapes.py.

I intend to get polygon-style targets (instead of masks) in the roi head, this is useful in implementing many contour-based instance segmentation methods like deep-snake, polarmask.

ZwwWayne commented 3 years ago

It seems that there is some incompatibility between the polygon mask and cityscapes. Please @yhcao6 have a check on that.