diff --git a/.gitignore b/.gitignore index f2913e4..9e1cc96 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ output/ .venv/ .env !tests/files/* +.idea diff --git a/README.md b/README.md index 27d449e..fb16d28 100644 --- a/README.md +++ b/README.md @@ -2655,6 +2655,46 @@ client.download_dataset_objects( ) ``` +### Update Dataset Object +```python +dataset_object = client.update_dataset_object( + dataset_id="YOUR_DATASET_ID", + object_name="brushwood_dog.jpg", + tags=["dog"], # max 5 tags per dataset object. + annotations=[ + { + "keypoints": [ + { + "value": [ + 102.59, + 23.04, + 1 + ], + "key": "head" + } + ], + "attributes": [ + { + "value": "Scottish field", + "key": "kind" + } + ], + "confidenceScore": 0, + "rotation": 0, + "points": [ + 0 + ], + "value": "dog", + "type": "bbox" # type can be 'bbox', 'segmentation'. + } + ], + custom_metadata={ + "key": "value", + "metadata": "metadata-value" + } +) +``` + ### Delete Dataset Object Delete a single dataset object. diff --git a/examples/update_dataset_object.py b/examples/update_dataset_object.py new file mode 100644 index 0000000..559a30f --- /dev/null +++ b/examples/update_dataset_object.py @@ -0,0 +1,12 @@ +from pprint import pprint + +import fastlabel + +client = fastlabel.Client() + +dataset_object = client.update_dataset_object( + dataset_id="YOUR_DATASET_ID", + object_name="OBJECT_NAME", + tags=["TAG1", "TAG2"], +) +pprint(dataset_object) diff --git a/fastlabel/__init__.py b/fastlabel/__init__.py index 021ace3..fc0acda 100644 --- a/fastlabel/__init__.py +++ b/fastlabel/__init__.py @@ -4043,7 +4043,10 @@ def download_dataset_objects( for _type, objects in object_map.items(): base_path = download_path / _type with ThreadPoolExecutor(max_workers=4) as executor: - futures = [executor.submit(self.__download_dataset_object, base_path, obj) for obj in objects] + futures = [ + executor.submit(self.__download_dataset_object, base_path, obj) + for obj in objects + ] wait(futures) # check specification @@ -4113,6 +4116,24 @@ def create_dataset_object( payload["customMetadata"] = custom_metadata return self.api.post_request(endpoint, payload=payload) + def update_dataset_object( + self, + dataset_id: str, + object_name: str, + tags: Optional[List[str]] = None, + annotations: Optional[List[dict]] = None, + custom_metadata: Optional[dict] = None, + ) -> dict: + endpoint = "dataset-objects-v2" + payload = {"datasetId": dataset_id, "objectName": object_name} + if tags is not None: + payload["tags"] = tags + if annotations is not None: + payload["annotations"] = annotations + if custom_metadata is not None: + payload["customMetadata"] = custom_metadata + return self.api.put_request(endpoint, payload=payload) + def delete_dataset_object(self, dataset_id: str, object_name: str) -> None: """ Delete a dataset object.