cocodataset / cocoapi

COCO API - Dataset @ http://cocodataset.org/
Other
6.1k stars 3.76k forks source link

Is there a python script that converts the synthetically generated image masks into coco json format #250

Open AhmadShaik opened 5 years ago

AhmadShaik commented 5 years ago

I am working on a model where the training data is completely generated synthetically. Since I have used synthetic data generators I have training images and its related masks. I am searching for some implementation which takes the masks as input and generates the json file in coco api format.

If there is no such implementation readily available, then please mention the necessary steps to generate the json file from the mask images.

Thank you.

jsbroks commented 5 years ago

I'm working on a lib https://github.com/jsbroks/imantics. It's not complete but it might help you do what you are asking

from imantics import Mask, Image, Category

image = Image.from_path('path/to/image.png')
image.add(Mask(array), category=Category("Category Name"))

# JSON of coco
coco_json = image.export(style='coco')
# Saves to file
image.save('coco/annotation.json', style='coco')
AhmadShaik commented 5 years ago

@jsbroks thank you very much for your response. I will quickly use your logic and share my result

rakehsaleem commented 4 years ago

Hello @AhmadShaik !!,

I'm working on a similar project in which I have test datasets with their respective annotations in .png format. Have you tried the procedure mentioned above by @jsbroks, and does it work? Were you able to get Success? If yes, could you share your script? Any other useful pointer will also be grateful. Thank you

anson-07 commented 3 years ago

I'm working on a lib https://github.com/jsbroks/imantics. It's not complete but it might help you do what you are asking

from imantics import Mask, Image, Category

image = Image.from_path('path/to/image.png')
image.add(Mask(array), category=Category("Category Name"))

# JSON of coco
coco_json = image.export(style='coco')
# Saves to file
image.save('coco/annotation.json', style='coco')

Is there any way to take into consideration of multiple images before exporting the full JSON file with all the images included?

yashdutt20 commented 3 years ago

Hey @anson-07 , @rakehsaleem , @AhmadShaik and @jsbroks , was this method able to produce the corresponding annotations from the rgb masks? I have generated the rgb segmentation masks and would like to create the annotation file as well.

rakehsaleem commented 3 years ago

@yashdutt20, Well, back in the day when I wanted to create a .json annotated file from RGB masks, I tried to give it a shot and couldn't get success or at least I couldn't use it in my project. But I tried to follow this guy's work (link) and I did get some reasonable results. Since this was just a hobby activity, I do not have a proper script but you can use the link to follow along the lines. Hope this helps!