Skip to content

Commit babd074

Browse files
Merge pull request #209 from fastlabel/feature/api-datset-object-annotations
Feature/api datset object annotations
2 parents aea2324 + 0d63d64 commit babd074

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ output/
1616
.venv/
1717
.env
1818
!tests/files/*
19+
.idea

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,46 @@ client.download_dataset_objects(
26552655
)
26562656
```
26572657

2658+
### Update Dataset Object
2659+
```python
2660+
dataset_object = client.update_dataset_object(
2661+
dataset_id="YOUR_DATASET_ID",
2662+
object_name="brushwood_dog.jpg",
2663+
tags=["dog"], # max 5 tags per dataset object.
2664+
annotations=[
2665+
{
2666+
"keypoints": [
2667+
{
2668+
"value": [
2669+
102.59,
2670+
23.04,
2671+
1
2672+
],
2673+
"key": "head"
2674+
}
2675+
],
2676+
"attributes": [
2677+
{
2678+
"value": "Scottish field",
2679+
"key": "kind"
2680+
}
2681+
],
2682+
"confidenceScore": 0,
2683+
"rotation": 0,
2684+
"points": [
2685+
0
2686+
],
2687+
"value": "dog",
2688+
"type": "bbox" # type can be 'bbox', 'segmentation'.
2689+
}
2690+
],
2691+
custom_metadata={
2692+
"key": "value",
2693+
"metadata": "metadata-value"
2694+
}
2695+
)
2696+
```
2697+
26582698
### Delete Dataset Object
26592699

26602700
Delete a single dataset object.

examples/update_dataset_object.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pprint import pprint
2+
3+
import fastlabel
4+
5+
client = fastlabel.Client()
6+
7+
dataset_object = client.update_dataset_object(
8+
dataset_id="YOUR_DATASET_ID",
9+
object_name="OBJECT_NAME",
10+
tags=["TAG1", "TAG2"],
11+
)
12+
pprint(dataset_object)

fastlabel/__init__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4043,7 +4043,10 @@ def download_dataset_objects(
40434043
for _type, objects in object_map.items():
40444044
base_path = download_path / _type
40454045
with ThreadPoolExecutor(max_workers=4) as executor:
4046-
futures = [executor.submit(self.__download_dataset_object, base_path, obj) for obj in objects]
4046+
futures = [
4047+
executor.submit(self.__download_dataset_object, base_path, obj)
4048+
for obj in objects
4049+
]
40474050
wait(futures)
40484051

40494052
# check specification
@@ -4113,6 +4116,24 @@ def create_dataset_object(
41134116
payload["customMetadata"] = custom_metadata
41144117
return self.api.post_request(endpoint, payload=payload)
41154118

4119+
def update_dataset_object(
4120+
self,
4121+
dataset_id: str,
4122+
object_name: str,
4123+
tags: Optional[List[str]] = None,
4124+
annotations: Optional[List[dict]] = None,
4125+
custom_metadata: Optional[dict] = None,
4126+
) -> dict:
4127+
endpoint = "dataset-objects-v2"
4128+
payload = {"datasetId": dataset_id, "objectName": object_name}
4129+
if tags is not None:
4130+
payload["tags"] = tags
4131+
if annotations is not None:
4132+
payload["annotations"] = annotations
4133+
if custom_metadata is not None:
4134+
payload["customMetadata"] = custom_metadata
4135+
return self.api.put_request(endpoint, payload=payload)
4136+
41164137
def delete_dataset_object(self, dataset_id: str, object_name: str) -> None:
41174138
"""
41184139
Delete a dataset object.

0 commit comments

Comments
 (0)