Create MS COCO style dataset

user20112015 picture user20112015 · Aug 7, 2017 · Viewed 10.6k times · Source

How to create a MS COCO style dataset to use with TensorFlow? Does anyone have an experience with this? I have images, and annotations, as well as ground truth masks. I need to convert them to be compatible with MS COCO and any help is appreciated. I can't find any open source tool to create COCO style JSON annotations.

TensorFlow MS COCO reads JSON files which I'm not very experienced with.

Answer

jsbroks picture jsbroks · Jan 20, 2019

I'm working on a python library which has many useful classes and functions for doing this. It's called Image Semantics.

Here is an example of adding masks and exporting them in COCO format:

from imantics import Mask, Image, Category

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

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