Mask_RCNN icon indicating copy to clipboard operation
Mask_RCNN copied to clipboard

How to join single .json to one annotation.json file as MS COCO

Open AliceDinh opened this issue 6 years ago • 8 comments

Hi, I used labelme to create .json file for each image of my own, but I want to join them into one file annotation.json file as the one in MS COCO, please show me how, thanks

AliceDinh avatar Mar 16 '18 10:03 AliceDinh

I guess you will have to write your own method to put all that together. The json file is just a formatted text so you can find a way to read each file one by one, take the required info you need and save it into a single file. The coco json file structure was explained by me in https://github.com/matterport/Mask_RCNN/issues/297

fastlater avatar Mar 19 '18 01:03 fastlater

@fastlater: thanks for your help. The annotations folder contains .json files that I don't quite get the differences among them and the relation between those files. I am mentioning captions_train2014.json; captions_val2014.json; instances_train2014.json and instances_val2014.json. Can you help me with this? When we train the model, from coco.py, only instances_train2014.json and instances_val2014.json are used, neither captions files, so the caption-ones are for what?

AliceDinh avatar Mar 20 '18 03:03 AliceDinh

@AliceDinh Captions files are for generating a sentence to describe the image. For image caption.

Yiman-GO avatar Mar 22 '18 02:03 Yiman-GO

@AliceDinh you can use labelme2coco package to convert your annotations to coco format. It is really easy.

Installation:

pip install labelme2coco

Usage:

# import package
import labelme2coco

# set directory that contains labelme annotations and image files
labelme_folder = "tests/data/labelme_annot"

# set path for coco json to be saved
save_json_path = "tests/data/test_coco.json"

# conert labelme annotations to coco
labelme2coco.convert(labelme_folder, save_json_path)

fcakyon avatar Jun 02 '20 14:06 fcakyon

@fcakyon I tried using the code you provided to convert labelme annotations to coco format but I'm getting this error "AttributeError: module 'labelme2coco' has no attribute 'convert'" . Could you please assist on the way forward?

loyanie avatar Oct 06 '20 21:10 loyanie

@loyanie Can you tell me more on your setup? Are you on Linux? Have you installed the package via pip or did you setup from the source? If from pip, which version of the package have you installed? Are you on a conda environment? What is your Python version?

Im asking these questions because I have no issues using the "convert" method.

fcakyon avatar Oct 08 '20 08:10 fcakyon

@loyanie Can you tell me more on your setup? Are you on Linux? Have you installed the package via pip or did you setup from the source? If from pip, which version of the package have you installed? Are you on a conda environment? What is your Python version?

Im asking these questions because I have no issues using the "convert" method.

I'm currently using windows 10 installed with anaconda and python 3.7.3, the labelme2coco package was installed using pip command.

loyanie avatar Oct 08 '20 20:10 loyanie

yes...thank you .. labelme2coco is installed for me ...thanks a lot

sathishrajembedded avatar Mar 11 '24 11:03 sathishrajembedded