cocodataset / panopticapi

COCO 2018 Panoptic Segmentation Task API (Beta version)
Other
418 stars 185 forks source link

Key error when running panoptic2detection_coco_format.py #10

Closed Loerbri closed 5 years ago

Loerbri commented 6 years ago

When running the script with the following arguments:

--input_json_file "panoptic_train2017.json" --segmentations_folder "stuff_train2017_pixelmaps" --output_json_file "my_folder" --categories_json_file "~/panopticapi/panoptic_coco_categories.json" --things_only

I get the following error:

CONVERTING... COCO panoptic format: Segmentation folder: stuff_train2017_pixelmaps JSON file: panoptic_train2017.json TO COCO detection format JSON file: train_semantic_seg Saving only segments of things classes.

Reading annotation information from panoptic_train2017.json Number of cores: 8, images per core: 14786 Core: 0, 0 from 14786 images processed Caught exception in worker thread: Traceback (most recent call last): File "/home/nicolas/panopticapi/converters/utils.py", line 14, in wrapper return f(*args, kwargs) File "/home/nicolas/panopticapi/converters/panoptic2detection_coco_format.py", line 61, in convert_panoptic_to_detection_coco_format_single_core segm_info['segmentation'] = COCOmask.encode(np.asfortranarray(mask))[0] KeyError: 0 multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/home/nicolas/.pyenv/versions/3.6.0/lib/python3.6/multiprocessing/pool.py", line 119, in worker result = (True, func(*args, *kwds)) File "/home/nicolas/panopticapi/converters/utils.py", line 18, in wrapper raise e File "/home/nicolas/panopticapi/converters/utils.py", line 14, in wrapper return f(args, kwargs) File "/home/nicolas/panopticapi/converters/panoptic2detection_coco_format.py", line 61, in convert_panoptic_to_detection_coco_format_single_core segm_info['segmentation'] = COCOmask.encode(np.asfortranarray(mask))[0] KeyError: 0 """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/nicolas/panopticapi/converters/panoptic2detection_coco_format.py", line 153, in args.things_only) File "/home/nicolas/panopticapi/converters/panoptic2detection_coco_format.py", line 109, in convert_panoptic_to_detection_coco_format annotations_coco_detection.extend(p.get()) File "/home/nicolas/.pyenv/versions/3.6.0/lib/python3.6/multiprocessing/pool.py", line 608, in get raise self._value KeyError: 0

I tried to remove the [0] in the line segm_info['segmentation'] = COCOmask.encode(np.asfortranarray(mask))[0] which resulted in

KeyError: 'color'

later on. Any help would be much appreciated.

kevinj22 commented 6 years ago

--input_json_file "panoptic_train2017.json" --segmentations_folder "stuff_train2017_pixelmaps" --output_json_file "my_folder" --categories_json_file "~/panopticapi/panoptic_coco_categories.json" --things_only

Your argument is things only but your segmentation PNG's are for stuff. Perhaps this is the issue?

If so set your segmentations_folder to the results of unzipping the panoptic_train2017.zip file.

Another guess would be to adjust the popping of the color category attribute here:

for category in d_coco['categories']:
        if things_only and category['isthing'] != 1:
            continue
        category.pop('isthing')

        try:
            category.pop('color')
        except:
            pass

        categories_coco_detection.append(category)
    d_coco['categories'] = categories_coco_detection

The key error at this point in time indicates to me there is no need to remove the 'color' key of the current category dictionary. Thus I wrapped it in a try / except block.

Loerbri commented 5 years ago

Thank you very much. I was indeed reading from the wrong segmentation folder.

ranjiewwen commented 5 years ago

i meet another problem int panoptic2detection_coco_format.py funtion : convert_panoptic_to_detection_coco_format() as follow:

    with open(output_json_file, 'w') as f:
        json.dump(d_coco, f)

display error:

   raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'0b7i51O001O1O1O2N4L2N00000000000000N2N2M3N200O100

i use python3.5 ; i have looked up some information and didn't solve it ; can you help ? thanks!

kevinj22 commented 5 years ago

I'm not sure about this but try json.dumps(dcoco). dumps is for strings I believe: https://realpython.com/python-json/

ranjiewwen commented 5 years ago

i meet another problem int panoptic2detection_coco_format.py funtion : convert_panoptic_to_detection_coco_format() as follow:

    with open(output_json_file, 'w') as f:
        json.dump(d_coco, f)

display error:

   raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'0b7i51O001O1O1O2N4L2N00000000000000N2N2M3N200O100

i use python3.5 ; i have looked up some information and didn't solve it ; can you help ? thanks!