voxel51 / voxel51/fiftyone

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

Open
#4,792 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
11.1k
Forks
822
Avg merge
2d 4h
Merged PRs (30d)
122

Description

### Describe the problem

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

```python
# 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:
```python
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

```python
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
- [x] No. I cannot contribute a bug fix at this time

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.