Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key error when running panoptic2detection_coco_format.py #10

Closed
Loerbri opened this issue Sep 7, 2018 · 5 comments
Closed

Key error when running panoptic2detection_coco_format.py #10

Loerbri opened this issue Sep 7, 2018 · 5 comments

Comments

@Loerbri
Copy link

Loerbri commented Sep 7, 2018

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
Copy link

kevinj22 commented Sep 8, 2018

--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
Copy link
Author

Loerbri commented Sep 10, 2018

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

@Loerbri Loerbri closed this as completed Sep 10, 2018
@ranjiewwen
Copy link

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
Copy link

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

@ranjiewwen
Copy link

ranjiewwen commented Nov 27, 2018

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!

  for segm_info in annotation['segments_info']:
            if things_only and categories[segm_info['category_id']]['isthing'] != 1:
                continue
            mask = (pan == segm_info['id']).astype(np.uint8)
            mask = np.expand_dims(mask, axis=2)
            mask=COCOmask.encode(np.asfortranarray(mask))[0]
            # 'counts' is returned as binary in Python 3, decode it into a UTF8 string
            mask['counts'] = mask['counts'].decode('utf8')

            segm_info.pop('id')
            segm_info['image_id'] = annotation['image_id']
            segm_info['segmentation'] = mask
            annotations_detection.append(segm_info)
  • best way to solve problem: use python2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants