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

Import pre-annotation tasks with labels #7109

Closed
JasonSloan opened this issue Feb 19, 2025 · 7 comments
Closed

Import pre-annotation tasks with labels #7109

JasonSloan opened this issue Feb 19, 2025 · 7 comments

Comments

@JasonSloan
Copy link

JasonSloan commented Feb 19, 2025

Hi team!

I had plenty of images with corresponding annotation-files. I wanted to import them into label-studio and made further annotations.
The images were stored in the linux server as the same place as the label-studio service started.
During the process of trying, I got two questions.

First, I tried to specify the aboslute path of the image and import it but failed, because label-studio couldnt find the image and I didnt know why.
I was sure the image existed in that path.
The content of the json file is below:
[ { "data": { "image": "/root/datasets/test/1.jpg" }, "predictions": [ { "model_version": "one", "score": 0.5, "result": [ { "id": "result1", "type": "rectanglelabels", "from_name": "label", "to_name": "image", "original_width": 600, "original_height": 403, "image_rotation": 0, "value": { "rotation": 0, "x": 57.96, "y": 25.11, "width": 6.40, "height": 25.00, "rectanglelabels": [ "Person" ] } } ] } ] } ]

Second I changed the 'image' variable to a uploaded task url and worked fine, but another problem raised.
The rectangle didnt show its label name though I had specified it (see the json content above, its name should be "Person").

Image

Can you help me with these two questions? Thanks very much!

@heidi-humansignal
Copy link
Collaborator

Hello,

Thank you for contacting Label Studio,

Could you please try the following suggestion and let us know it has worked out!

1. Importing Using an Absolute Image Path
Label Studio does not support supplying a raw absolute file system path (e.g., /root/datasets/test/1.jpg) in the JSON task. Instead, Label Studio uses a local file serving mechanism that requires you to:
• Set the environment variable LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true and define
LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT to the directory where your images reside (for example, /root/datasets).
• In your JSON, reference images relative to that document root using the URL pattern:
"/data/local-files/?d=<relative_path>".
For your case, if your images are under /root/datasets/test/, then the image should be referenced as:
"/data/local-files/?d=test/1.jpg"
rather than using the absolute path. This way, when Label Studio receives the task, its built-in file serving logic can resolve the correct local file.

2. Annotation Label Not Displaying in the Rectangle
If you switched the image reference to a URL (i.e. one that works with Label Studio’s local files serving) and the image loads but the rectangle does not show the expected label ("Person"), consider the following:

• Labeling Configuration Consistency:
Ensure that the project’s labeling configuration (the XML used to define the annotation interface) includes a <Label> element with the value "Person" and that its name matches the from_name specified in the JSON. For example, if your JSON annotation uses:

"from_name": "label"

your labeling configuration should include something like:

<RectangleLabels name="label" toName="image"> <Label value="Person" background="green"/> </RectangleLabels>

• Case Sensitivity and Mapping:
Label Studio treats the labels as case sensitive. Verify that the string "Person" exactly matches what is defined in your labeling interface.
• Annotation Format:
Make sure that the annotations are formatted correctly. The "rectanglelabels" field should be an array of strings (as yours is), and other values such as coordinates, rotation, and dimensions should be numeric and within bounds. Any mismatch or misconfiguration in the control tag (or a discrepancy between the JSON and the interface’s from_name / to_name values) may cause the label name not to be rendered in the UI.

By doing the following:

  1. Configure Local Files Properly
  • Set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT (e.g., /root/datasets) when starting Label Studio.
  • In the JSON, replace the absolute image path with a URL like "/data/local-files/?d=test/1.jpg".
  1. Ensure Proper Label Mapping
  • Update your project’s label configuration to include the label "Person" under the correct control tag.
  • Verify that the annotation JSON’s from_name field (in this case "label") exactly matches the name used in your configuration.
    These adjustments should resolve both the image path issue and the missing label display on your rectangle annotation. Let us know if you need additional support!

Comment by Oussama Assili
Workflow Run

@JasonSloan
Copy link
Author

Hello,

Thank you for contacting Label Studio,

Could you please try the following suggestion and let us know it has worked out!

1. Importing Using an Absolute Image Path Label Studio does not support supplying a raw absolute file system path (e.g., /root/datasets/test/1.jpg) in the JSON task. Instead, Label Studio uses a local file serving mechanism that requires you to: • Set the environment variable LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true and define LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT to the directory where your images reside (for example, /root/datasets). • In your JSON, reference images relative to that document root using the URL pattern: "/data/local-files/?d=<relative_path>". For your case, if your images are under /root/datasets/test/, then the image should be referenced as: "/data/local-files/?d=test/1.jpg" rather than using the absolute path. This way, when Label Studio receives the task, its built-in file serving logic can resolve the correct local file.

2. Annotation Label Not Displaying in the Rectangle If you switched the image reference to a URL (i.e. one that works with Label Studio’s local files serving) and the image loads but the rectangle does not show the expected label ("Person"), consider the following:

• Labeling Configuration Consistency: Ensure that the project’s labeling configuration (the XML used to define the annotation interface) includes a <Label> element with the value "Person" and that its name matches the from_name specified in the JSON. For example, if your JSON annotation uses:

"from_name": "label"

your labeling configuration should include something like:

<RectangleLabels name="label" toName="image"> <Label value="Person" background="green"/> </RectangleLabels>

• Case Sensitivity and Mapping: Label Studio treats the labels as case sensitive. Verify that the string "Person" exactly matches what is defined in your labeling interface. • Annotation Format: Make sure that the annotations are formatted correctly. The "rectanglelabels" field should be an array of strings (as yours is), and other values such as coordinates, rotation, and dimensions should be numeric and within bounds. Any mismatch or misconfiguration in the control tag (or a discrepancy between the JSON and the interface’s from_name / to_name values) may cause the label name not to be rendered in the UI.

By doing the following:

  1. Configure Local Files Properly
  • Set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT (e.g., /root/datasets) when starting Label Studio.
  • In the JSON, replace the absolute image path with a URL like "/data/local-files/?d=test/1.jpg".
  1. Ensure Proper Label Mapping
  • Update your project’s label configuration to include the label "Person" under the correct control tag.
  • Verify that the annotation JSON’s from_name field (in this case "label") exactly matches the name used in your configuration.
    These adjustments should resolve both the image path issue and the missing label display on your rectangle annotation. Let us know if you need additional support!

Comment by Oussama Assili
Workflow Run

Thanks for your suggestions!

Here are the experiment results.

  1. Importing Using an Absolute Image Path

Not worked. Below is the screenshot of environment varables I had already set, but still the image(1.jpg) wouldnt show up.
And it was weird that, the images that I had already imported using local-storage entry in other projects could show up in this way while the images that never imported by other projects couldnt.

Image

Image

  1. Annotation Label Not Displaying in the Rectangle

This is solved following your suggestion.

So can you help me further analyze problem one? Many thanks!

@JasonSloan
Copy link
Author

HI, are there any solutions yet?

Hello,

Thank you for contacting Label Studio,

Could you please try the following suggestion and let us know it has worked out!

1. Importing Using an Absolute Image Path Label Studio does not support supplying a raw absolute file system path (e.g., /root/datasets/test/1.jpg) in the JSON task. Instead, Label Studio uses a local file serving mechanism that requires you to: • Set the environment variable LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true and define LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT to the directory where your images reside (for example, /root/datasets). • In your JSON, reference images relative to that document root using the URL pattern: "/data/local-files/?d=<relative_path>". For your case, if your images are under /root/datasets/test/, then the image should be referenced as: "/data/local-files/?d=test/1.jpg" rather than using the absolute path. This way, when Label Studio receives the task, its built-in file serving logic can resolve the correct local file.

2. Annotation Label Not Displaying in the Rectangle If you switched the image reference to a URL (i.e. one that works with Label Studio’s local files serving) and the image loads but the rectangle does not show the expected label ("Person"), consider the following:

• Labeling Configuration Consistency: Ensure that the project’s labeling configuration (the XML used to define the annotation interface) includes a <Label> element with the value "Person" and that its name matches the from_name specified in the JSON. For example, if your JSON annotation uses:

"from_name": "label"

your labeling configuration should include something like:

<RectangleLabels name="label" toName="image"> <Label value="Person" background="green"/> </RectangleLabels>

• Case Sensitivity and Mapping: Label Studio treats the labels as case sensitive. Verify that the string "Person" exactly matches what is defined in your labeling interface. • Annotation Format: Make sure that the annotations are formatted correctly. The "rectanglelabels" field should be an array of strings (as yours is), and other values such as coordinates, rotation, and dimensions should be numeric and within bounds. Any mismatch or misconfiguration in the control tag (or a discrepancy between the JSON and the interface’s from_name / to_name values) may cause the label name not to be rendered in the UI.

By doing the following:

  1. Configure Local Files Properly
  • Set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT (e.g., /root/datasets) when starting Label Studio.
  • In the JSON, replace the absolute image path with a URL like "/data/local-files/?d=test/1.jpg".
  1. Ensure Proper Label Mapping
  • Update your project’s label configuration to include the label "Person" under the correct control tag.
  • Verify that the annotation JSON’s from_name field (in this case "label") exactly matches the name used in your configuration.
    These adjustments should resolve both the image path issue and the missing label display on your rectangle annotation. Let us know if you need additional support!

Comment by Oussama Assili
Workflow Run

HI, are there any solutions yet?

@heidi-humansignal
Copy link
Collaborator

Hello,

can you please confirm if the issue you are still encountering is at the level of Absolute path of images ?

Comment by Oussama Assili
Workflow Run

@JasonSloan
Copy link
Author

Hello,

can you please confirm if the issue you are still encountering is at the level of Absolute path of images ?

Comment by Oussama Assili
Workflow Run

Hello!

Yes I can. If I give the path the example image and import the json file as a new project, everything will be fine.

Detail here. Ignore the label name and position, just a demo.

Image

Contents of json file here:

[
    {
        "data": {
            "image": "/static/samples/sample.jpg"
        },
        "predictions": [
            {
                "model_version": "one",
                "score": 0.5,
                "result": [
                    {
                        "id": "result1",
                        "type": "rectanglelabels",
                        "from_name": "label",
                        "to_name": "image",
                        "original_width": 1920,
                        "original_height": 1080,
                        "image_rotation": 0,
                        "value": {
                            "rotation": 0,
                            "x": 57.96,
                            "y": 25.11,
                            "width": 6.40,
                            "height": 25.00,
                            "rectanglelabels": [
                                "person_easy"
                            ]
                        }
                    }
                ]
            }
        ]
    }
]

@JasonSloan
Copy link
Author

JasonSloan commented Mar 5, 2025

Hello,

can you please confirm if the issue you are still encountering is at the level of Absolute path of images ?

Comment by Oussama Assili
Workflow Run

Oh I just work this out! Following the instructions here

I need to upload the images using cloud storage(local storage), but dont press sync, then upload the json file specifying the image path and it will work fine.

Thanks a lot!

@heidi-humansignal
Copy link
Collaborator

Perfect! we are happy to assist you!

Please do not hesitate to reach out if you have additional questions! Have a lovely day.

Comment by Oussama Assili
Workflow Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants