Unity-Technologies/pysolotools

SOLO2COCOConverter throws keyerror "instances" when no labeled objects in image

TimSchoonbeek opened this issue · 3 comments

Hi,

Due to the settings used in my dataset generation, apparently not all images have a visible object (around 1/1000 images don't have 2D bounding boxes).
This causes the SOLO2COCOConverter to crash with a keyerror "instances" error.

Perhaps the converter can be updated to just skip images if there is no label, rather than crash? As I don't know which images don't have any bounding boxes, I now have to write a separate script which deletes these instances this before feeding the data to the converter.

@TimSchoonbeek Thanks for the feedback. I'll definitely add this to the backlog because you are correct, we should handle this case more gracefully.

Hi,

Due to the settings used in my dataset generation, apparently not all images have a visible object (around 1/1000 images don't have 2D bounding boxes). This causes the SOLO2COCOConverter to crash with a keyerror "instances" error.

Perhaps the converter can be updated to just skip images if there is no label, rather than crash? As I don't know which images don't have any bounding boxes, I now have to write a separate script which deletes these instances this before feeding the data to the converter.

@TimSchoonbeek you just saved me from giving up on the SOLO2COCO converter. Replacing one faulty label fixed it for me. So thank you!

@StevenBorkman I'd also recommend to add the same fix to your Pysolo Fiftyone as that also crashes when one label is missing on a sequence. I added a comment to an issue posted there too.

I fixed this for myself by editing the dataclasses_json/core.py lines 170-175 to

        # The field should be skipped from being added
        # to init_kwargs as it's not intended as a constructor argument.
        if not field.init:
            continue
        if not field.name in kvs:
            field_value = None
            field_type = None
        else:
            field_value = kvs[field.name]
            field_type = types[field.name]
        if field_value is None:

Works for me, but I guess you could add this sort of error checking further up the chain and just dumping in None if there's no bounding box.