Search code examples
jsonobject-detectionsingle-shot-detectorlabelme

How to Convert labelme json data to Pascal VOC format using labelme2voc.py


I have annotated images in label-me and the annotation is saved in .json file. I am trying to train a SSD object dictation model and I need data in Pascal VOC format. Label me has a file named labelme2voc.py I tried multiple time and failed each time the documentation regarding this is also very poor. Does anyone know how to convert json to Pascal VOC using these? any-other way would also be appreciated. I have 4 classes but each image conations upwards of 50 annotations.


Solution

  • First you need to download labelme2voc.py file and save to your computer (I saved inside the dataset folder).

    Then you need to create a "labels" file containing the label names you used, that needs to be similar to the one provided by labelme. You can also save this file inside the dataset folder.

    Then you're gonna run python3 labelme2voc.py data_annotaded data_dataset_voc --labels labels.txt

    You're gonne change data_annotaded by the path of the data you annotated (where the annotated json is located). And you're gonna change data_dataset_voc by any name you wish your output folder will be called.

    In my case I have the following folder structure:

    ├── labelme2voc.py 
    ├── labels.txt 
    ├── test_labelme 
    │   ├── 1.json
    │   ├── 1.png
    ..........
    │   ├── 9.json
    │   └── 9.png
    └── train_labelme
        ├── 1.json
        ├── 1.png
        ......
        ├── 3.json
        └── 3.png
    

    And I'm calling python3 labelme2voc.py train_labelme train_labelme/train_voc --labels labels.txt to generate the annotation.