label-studio icon indicating copy to clipboard operation
label-studio copied to clipboard

How to import COCO annotations (bounding boxes)

Open GabrielDornelles opened this issue 3 years ago • 13 comments

I have a COCO annotation file for my dataset (generated by my model). I want to refine the predicted bounding boxes. How do I import the coco format json file into the project? I've seen this Label-studio-converter but I don't know how to use it for this case.

GabrielDornelles avatar Aug 09 '22 16:08 GabrielDornelles

You need to do something like this

python -m venv env
source env/bin/activate
git clone https://github.com/heartexlabs/label-studio-converter.git
cd label-studio-converter
pip install -e . 

label-studio-converter import coco -h  # just print help

label-studio-converter import coco -i your-input-file.json -o output.json

then the converter prints instructions how to import a converted file to Label Studio. You will get output.json and label config XML file, so you need to 1 setup a new project in LS 2 set the label config 3 import output.json file

Related question: https://github.com/heartexlabs/label-studio/issues/808 Related PR: https://github.com/heartexlabs/label-studio-converter/pull/46

makseq avatar Aug 09 '22 23:08 makseq

Thanks! One more question if possible:

How should be the image path in this Label studio format?

image

I'm not getting the images with the annotations when loading

GabrielDornelles avatar Aug 10 '22 13:08 GabrielDornelles

Nvm! I've figured it out, it works with the path above, as long as I add that absolute path in the storage settings via UI

GabrielDornelles avatar Aug 10 '22 14:08 GabrielDornelles

Hi @GabrielDornelles @makseq,

I have added local storage path "/home/anang/images" in the settings and synced the local path to get the images. I am facing issue after importing the output.json file in label studio. The images are not getting imposed with the annotations on importing the output.json, instead I am getting new tasks from output.json resulting in duplicate tasks for the images. Below is the screen shots.

image

Can you please help me on how I can get the images loaded correctly with annotations in label studio

Anang1502 avatar Jan 23 '23 06:01 Anang1502

Hi @GabrielDornelles @makseq,

I have added local storage path "/home/anang/images" in the settings and synced the local path to get the images. I am facing issue after importing the output.json file in label studio. The images are not getting imposed with the annotations on importing the output.json, instead I am getting new tasks from output.json resulting in duplicate tasks for the images. Below is the screen shots.

image

Can you please help me on how I can get the images loaded correctly with annotations in label studio

Hi Anang!

From what I remember doing I've done this path:

  • Convert COCO anns to label-studio format (which is the one that supports loading anns with images)
  • Enable LOCAL_FILES_SERVING_ENABLED flag before launching label-studio (export LOCAL_FILES_SERVING_ENABLED=1 or add it in .bashrc)
  • Load label-studio json with the images in a new project
  • Add a storage of local-files where Absolute local path is the directory your images are pointing to in the annotation file

That done, everything worked as expected

GabrielDornelles avatar Jan 23 '23 12:01 GabrielDornelles

Hi Gabriel,

Thanks for reverting back. I followed these steps. But the issue was it seems with the image path in the output.json file created from label-studio-converter. I modified the path to make it point to the correct images directory path and it is working fine now.

Anang1502 avatar Jan 24 '23 19:01 Anang1502

good job

vansin avatar Apr 30 '23 10:04 vansin

Hey, I just imported this output.json to labelstudio, I can see images with annotations, but annotations are grey - not linked to classes ("rectanglelabels"). I have correct labeling interface. I dont know what I did wrong.

output.json: [ { "data": { "image": "/data/local-files/?d=FF\TEST\0006.png" }, "annotations": [ { "result": [ { "id": "eabad6846a", "type": "rectanglelabels", "value": { "x": 6.702127659574467, "y": 16.1507402422611, "width": 24.042553191489365, "height": 31.493943472409146, "rotation": 0, "rectanglelabels": "2salat" }, "to_name": "image", "from_name": "label_rectangles", "image_rotation": 0, "original_width": 2050, "original_height": 1620 } ]

Redalert277 avatar May 05 '23 10:05 Redalert277

Hi Gabriel,

Thanks for reverting back. I followed these steps. But the issue was it seems with the image path in the output.json file created from label-studio-converter. I modified the path to make it point to the correct images directory path and it is working fine now.

Hi, I also follow that steps and modified the path to point to the correct images directory path in the JSON file, but still got that issue. The path is "/home/ubuntu/paddle/PaddleDetection/label_studio_test/" a9dd722ab8f3c369a3d95eeae37f825 b1610e8f1f121fc0d242cb016a7c9c0

ttm43 avatar May 08 '23 00:05 ttm43

Hey, I just imported this output.json to labelstudio, I can see images with annotations, but annotations are grey - not linked to classes ("rectanglelabels"). I have correct labeling interface. I dont know what I did wrong.

output.json: [ { "data": { "image": "/data/local-files/?d=FF\TEST\0006.png" }, "annotations": [ { "result": [ { "id": "eabad6846a", "type": "rectanglelabels", "value": { "x": 6.702127659574467, "y": 16.1507402422611, "width": 24.042553191489365, "height": 31.493943472409146, "rotation": 0, "rectanglelabels": "2salat" }, "to_name": "image", "from_name": "label_rectangles", "image_rotation": 0, "original_width": 2050, "original_height": 1620 } ]

I had the same problem: for me the issue was that I needed to include the XML as a custom template under "labelling setup" when you create a project. I used label-studio-converter to convert some COCO annotations to label studio JSON. This creates a json file, but also an xml file. Copy and past the contents of the XML in the labelling setup tab.

victor-lovic avatar Jun 27 '23 15:06 victor-lovic

My COCO dataset JSON file contains empty list of segmentations...

WARNING:root:Segmentation in COCO is experimental
Traceback (most recent call last):
  File "/home/frta/.local/bin/label-studio-converter", line 33, in <module>
    sys.exit(load_entry_point('label-studio-converter', 'console_scripts', 'label-studio-converter')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frta/projects/***-pose-estimation/label-studio-converter/label_studio_converter/main.py", line 189, in main
    imports(args)
  File "/home/frta/projects/***-pose-estimation/label-studio-converter/label_studio_converter/main.py", line 171, in imports
    import_coco.convert_coco_to_ls(
  File "/home/frta/projects/***-pose-estimation/label-studio-converter/label_studio_converter/imports/coco.py", line 219, in convert_coco_to_ls
    item = create_segmentation(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/frta/projects/***-pose-estimation/label-studio-converter/label_studio_converter/imports/coco.py", line 54, in create_segmentation
    segmentation = annotation['segmentation'][0]
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

frippe75 avatar Nov 03 '23 16:11 frippe75

After reading everyone's responses, I have a few small questions, I hope you can help me I have an annotation model, it generates a COCO annotation file, I want to import the coco annotation file in Label-studio to further verify and improve the accuracy of the model annotation, how to import the coco json file into the project? Oh yes, I'm using a Linux operating system, and LS is installed with pip

jiangtangaaaa avatar Nov 15 '23 05:11 jiangtangaaaa

You need to do something like this你需要做这样的事情

python -m venv env
source env/bin/activate
git clone https://github.com/heartexlabs/label-studio-converter.git
cd label-studio-converter
pip install -e . 

label-studio-converter import coco -h  # just print help

label-studio-converter import coco -i your-input-file.json -o output.json

then the converter prints instructions how to import a converted file to Label Studio. You will get output.json and label config XML file, so you need to然后转换器会打印有关如何将转换后的文件导入 Label Studio 的说明。你会得到 output.json 和标签配置 XML 文件,所以你需要 1 setup a new project in LS1 在 LS 中设置一个新项目 2 set the label config2 设置标签配置 3 import output.json file3 导入output.json文件

Related question: #808 相关问题:#808 Related PR: HumanSignal/label-studio-converter#46相关公关:HumanSignal/label-studio-converter#46

When I type label-studio-converter import coco -i result.json -o output.json Tip: with open(input_file, encoding='utf8') as f: FileNotFoundError: [Errno 2] No such file or directory: '/home/wjt/PycharmProjects/pythonProject/label-studio-converter/result.json'

jiangtangaaaa avatar Nov 15 '23 06:11 jiangtangaaaa