Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import COCO annotations (bounding boxes) #2806

Open
GabrielDornelles opened this issue Aug 9, 2022 · 13 comments
Open

How to import COCO annotations (bounding boxes) #2806

GabrielDornelles opened this issue Aug 9, 2022 · 13 comments
Assignees
Labels
images Image annotation cases import question just a question

Comments

@GabrielDornelles
Copy link

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.

@makseq makseq added images Image annotation cases import question just a question labels Aug 9, 2022
@makseq
Copy link
Member

makseq commented Aug 9, 2022

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: #808
Related PR: HumanSignal/label-studio-converter#46

@makseq makseq closed this as completed Aug 9, 2022
@GabrielDornelles
Copy link
Author

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
Copy link
Author

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

@Anang1502
Copy link

Anang1502 commented Jan 23, 2023

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

@GabrielDornelles
Copy link
Author

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

@Anang1502
Copy link

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.

@vansin
Copy link

vansin commented Apr 30, 2023

good job

@Redalert277
Copy link

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
}
]

@ttm43
Copy link

ttm43 commented May 8, 2023

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

@victor-lovic
Copy link

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.

@frippe75
Copy link

frippe75 commented Nov 3, 2023

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

@jiangtangaaaa
Copy link

jiangtangaaaa commented Nov 15, 2023

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
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
images Image annotation cases import question just a question
Projects
None yet
Development

No branches or pull requests

10 participants