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

[BUG] Upload Annotations to LabelStudio Results in Key Error and Misaligned Boxes #4792

Open
1 of 3 tasks
aaugie opened this issue Sep 11, 2024 · 0 comments
Open
1 of 3 tasks
Labels
bug Bug fixes

Comments

@aaugie
Copy link

aaugie commented Sep 11, 2024

Describe the problem

Exporting annotations to Label Studio resulted in a key error on line 345 of labelstudio.py uploading file_ids

            # create tasks out of the uploaded files
            payload = json.dumps(
                {
                    "file_upload_ids": upload_resp.json()["file_upload_ids"],
                    "files_as_tasks_list": False,
                }
            )
            self._client.headers.update({"Content-Type": "application/json"})
            self._client.make_request(
                "POST", f"/api/projects/{project.id}/reimport", data=payload
            ) 

Error:

Traceback (most recent call last):
    File "/home/user/miniconda3/envs/yolo_env/lib/python3.12/site-packages/fiftyone/core/collections.py", line 8847, in annotate
    return foua.annotate(
           ^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/yolo_env/lib/python3.12/site-packages/fiftyone/utils/annotations.py", line 249, in annotate
    results = anno_backend.upload_annotations(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/yolo_env/lib/python3.12/site-packages/fiftyone/utils/labelstudio.py", line 146, in upload_annotations
    results = api.upload_samples(samples, anno_key, self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/yolo_env/lib/python3.12/site-packages/fiftyone/utils/labelstudio.py", line 460, in upload_samples
    uploaded_tasks = self._upload_tasks(project, tasks, predictions)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/yolo_env/lib/python3.12/site-packages/fiftyone/utils/labelstudio.py", line 347, in _upload_tasks
    "file_upload_ids": upload_resp.json()["file_upload_ids"],
                       ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'file_upload_ids'

A fix to the bug would be changing 'file_upload_ids' in the payload to 'import', which is what label studio api now returns. Annotations are then able to be uploaded along with images but the annotations are misaligned.

Code to reproduce issue

import fiftyone as fo
from pathlib import Path
from label_studio_sdk import Client

dataset = fo.load_dataset('dataset')

ls = Client(url='https://url.com', api_key='api_key')
print(ls.check_connection()) # checked for successful connection

api_key = 'api_key'
anno_key = "anno"
label_field = 'yolo_detections'
label_schema = {
    "yolo_detects": {
        "type": "detections",
        "classes": dataset.distinct("yolo_detections.detections.label"),
    },
}

dataset.annotate(anno_key, label_field=label_field, api_key=api_key, task_size=20,
              label_schema=label_schema, attributes=False, project_name='project_1',
              backend='labelstudio', url='https://url.com')

System information

  • **Linux Ubuntu 20.04
  • Python version (python --version): 3.12
  • FiftyOne version (fiftyone --version): 0.25.1
  • FiftyOne installed from (pip or source): pip
  • label-studio: 1.13.1
  • label-studio-sdk: 1.0.5

Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another
member of your organization be willing to contribute a fix for this bug to the
FiftyOne codebase?

  • Yes. I can contribute a fix for this bug independently
  • Yes. I would be willing to contribute a fix for this bug with guidance
    from the FiftyOne community
  • No. I cannot contribute a bug fix at this time
@aaugie aaugie added the bug Bug fixes label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

No branches or pull requests

1 participant