Detectron: convert_cityscapes_to_coco.py error:ValueError: too many values to unpack

Created on 12 Apr 2018  Â·  11Comments  Â·  Source: facebookresearch/Detectron

When I used convert_cityscapes_to_coco.py to convert cityscape to coco format,I got an error:
in instances2dict_with_polygons
contour, hier = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
ValueError: too many values to unpack

Thanks

Most helpful comment

@wuqi930907 Hi, I also get Warning: invalid contours. Did you solve this problem? Thank you!

All 11 comments

Hi @wuqi930907, cv2.findContours API changed in OpenCV 3.2 (see #9 for more info).

Since OpenCV 3.2, findContours() no longer modifies the source image but returns a modified image as the first of three return parameters.

If you're using OpenCV >= 3.2, try something like:

_, contour, hier = cv2.findContours(...)

My opencv's version is 3.4.12, I have modified the code to "_, contour, hier = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)", but when I used convert_cityscapes_to_coco.py again, I also got an Warning: invalid contours.
Is something wrong?
Thanks @ir413

@wuqi930907 Hi, I also get Warning: invalid contours. Did you solve this problem? Thank you!

Hello! Could you please tell me where to get the convert_cityscapes_to_coco.py?

@wuqi930907 could you fix the invalid contours issue?

@wuqi930907 ,same question:
Processed 0 images, 0 annotations
Traceback (most recent call last):
File "tools/convert_cityscapes_to_coco_bddFormat.py", line 212, in
convert_cityscapes_instance_only(datadir, outdir)
File "tools/convert_cityscapes_to_coco_bddFormat.py", line 168, in convert_cityscapes_instance_only
if obj['contours'] == []:
KeyError: u'contours'

@wuqi930907 @sidnav @lssily I think you could try:print (obj.keys())
and the result is :
['medDist', 'instID', 'distConf', 'labelID', 'pixelCount']

@krumo @wuqi930907 @sidnav I also happen to have the "invalid contours" issue. In the code I noticed that in the line where the error comes from they say:

print('Warning: invalid contours.')
continue  # skip non-instance categories

So maybe it is ok like this?

will this "invalid contours warning" affect the transformed dataset?

@Luodian I'd like to know that too.

A contour in this context is a python list of pixel positions enclosing a shape. An invalid contour is formed when you combine <= 4 such pixels given the function cv2.findContours was provided with cv2.CHAIN_APPROX_NONE as one of the arguments. Such a shape would resemble either a single pixel, a line, a triangle or a square with no pixels nothing inside them.

This might be helpful too. For more information about cv2.findContours, check this. Overall, these instances are meaningless and so are discarded. Hope it helps!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rbgirshick picture rbgirshick  Â·  3Comments

pacelu picture pacelu  Â·  3Comments

Adhders picture Adhders  Â·  3Comments

fangpengcheng95 picture fangpengcheng95  Â·  4Comments

junxiaoge picture junxiaoge  Â·  3Comments