Mask_RCNN icon indicating copy to clipboard operation
Mask_RCNN copied to clipboard

Converting json format

Open vsd-dev opened this issue 6 years ago • 5 comments

How to convert multilple jsons got from labelme annotation tool to the one that matches with COCO/BALLOON dataset?

vsd-dev avatar Mar 23 '19 15:03 vsd-dev

Do you want to combine multiple json files to one? If that is the case then you can use the VGG annotation tool, import all the json files together. It will combine the json files automatically.

monjurulkarim avatar Mar 29 '19 14:03 monjurulkarim

@sherlocked777 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

Hi @fcakyon Could you help me to solve this issue please?

Converting labelme annotations to COCO format:   0%|                               | 0/500 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "convert_.py", line 11, in <module>
    labelme2coco.convert(labelme_folder, save_json_path)
  File "/home/user/anaconda3/envs/mlp/lib/python3.7/site-packages/labelme2coco/__init__.py", line 32, in convert
    coco = get_coco_from_labelme_folder(labelme_folder)
  File "/home/user/anaconda3/envs/mlp/lib/python3.7/site-packages/labelme2coco/labelme2coco.py", line 44, in get_coco_from_labelme_folder
    width, height = Image.open(image_path).size
  File "/home/user/anaconda3/envs/mlp/lib/python3.7/site-packages/PIL/Image.py", line 3068, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'anno/..\\img\\0067.jpg'

Thank you

mountains-high avatar Jun 03 '22 08:06 mountains-high

image file and json should be in the same folder

abhay8051 avatar Sep 13 '22 05:09 abhay8051

hi @mountains-high, in your json file's "imagePath": "some_path" contains an image path. when you use lebelme2coco converter ,it find an image path and gave an above mentioned error message. so can you remove the path and define only the image name and try the convertion. it works for me

amuthalingeswaranbose avatar Sep 17 '22 11:09 amuthalingeswaranbose