-
Notifications
You must be signed in to change notification settings - Fork 185
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
TypeError: Object of type int64 is not JSON serializable #51
Comments
I have the same problem. I annotated the images using COCO Annotator. Thank you. |
The fix is simple, you have to typecast img_id -> int(img_id) in line 64 of detection2panoptic_coco_format.py This is because the code splits the list of image ids with numpy api in line 108, hence all these ints are converted to numpy.int64. With casting to python int, it becomes a serializable object and can be properly saved as json |
Thank you so much @Chris1nexus! I will try that. |
I tried it and it worked! Many thanks @Chris1nexus!! |
no problem m8 @dokunima |
Hi @Chris1nexus, sorry to bother you. I tried using the panoptic .json created for transfer learning on Coco panoptic segmentation (Detectron 2) but I get a KeyError id. I have looked at the .json but there is an "id" field in images. Please see the error below: extra_annotation_keys) /usr/local/lib/python3.7/dist-packages/pycocotools/coco.py in init(self, annotation_file) /usr/local/lib/python3.7/dist-packages/pycocotools/coco.py in createIndex(self) KeyError: 'id' |
ok that is about the pycocotools api though, not panopticapi, for new_id, ann in enumerate(annotations): then you take the json and set its annotations to the ones that you just modified with coco_json i am referring to this as specified in the coco standard |
@Chris1nexus many thanks for the link and the suggestion. I will have a look at the link and try that. |
let me know if it worked also for you @dokunima |
@Chris1nexus. Sure thing. I have been very busy on another project. I will try it when I have some time. Thank you. |
it works, thanks a lot!!! |
Hi @Chris1nexus, sorry to bother you. I have a custom dataset and want to convert its instance segmentation format to panoptic segmentation format, but I get the following error.Do you know how to fix this error? Please see the error below:
|
Hello! Sorry for the late answer, anyway that happens because for a given image, one or more of the associated instance masks overlap(check line 54 to 71 of that script). The why: The fix: |
Thanks for your suggestion, I will check the code. |
Hi @Chris1nexus , Thank you for your previous reply. I removed this
and got the data in panoptic segmentation format, but when I trained with mmdetection's panoptic FPN, I got the following error:
I used a custom dataset, this dataset has coco instance segmentation format, there is only one stuff class is the background class, the other all thing class. I checked the generated panoptic segmentation data and found that each of the images is not labeled with a background class, and I'm not sure if this is the reason for the error. I want to predict both the instance segmentation mask and the semantic segmentation mask of the image by the panoptic segmentation model, but I am troubled by the panoptic segmentation format conversion for a long time. |
I have the same error |
Running detection2panoptic_coco_format.py first fails on untouched fresh unzipped coco-things
I've modified to code to skip over anything with an overlap and then the png maps load but the JSON conversion fails at saving
JSON Serialization Error. Something about d_coco['annotations'] fails even when using python ints
Even when I convert both the bounding boxes and area to python integers I still get the error. If I try to copy a sample to a jupyter notebook it has no problem saving to JSON
The text was updated successfully, but these errors were encountered: