Skip to content

Commit 5e4ae0b

Browse files
authored
Merge pull request #180 from fastlabel/feature/dataset-objects-api
feat: dataset objects api
2 parents 9fbcb0a + 8e57134 commit 5e4ae0b

File tree

7 files changed

+157
-90
lines changed

7 files changed

+157
-90
lines changed

README.md

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,11 +2477,41 @@ Create object in the dataset.
24772477
The types of objects that can be created are "image", "video", and "audio".
24782478
There are type-specific methods. but they can be used in the same way.
24792479

2480+
Created object are automatically assigned to the "latest" dataset version.
2481+
24802482
```python
24812483
dataset_object = client.create_dataset_object(
2482-
dataset_version_id="YOUR_DATASET_VERSION_ID",
2484+
dataset="YOUR_DATASET_NAME",
24832485
name="brushwood_dog.jpg",
24842486
file_path="./brushwood_dog.jpg",
2487+
tags=["dog"], # max 5 tags per dataset object.
2488+
annotations=[
2489+
{
2490+
"keypoints": [
2491+
{
2492+
"value": [
2493+
102.59,
2494+
23.04,
2495+
1
2496+
],
2497+
"key": "head"
2498+
}
2499+
],
2500+
"attributes": [
2501+
{
2502+
"value": "Scottish field",
2503+
"key": "kind"
2504+
}
2505+
],
2506+
"confidenceScore": 0,
2507+
"rotation": 0,
2508+
"points": [
2509+
0
2510+
],
2511+
"value": "dog",
2512+
"type": "bbox" # type can be 'bbox', 'segmentation'.
2513+
}
2514+
]
24852515
)
24862516
```
24872517

@@ -2496,7 +2526,46 @@ See API docs for details.
24962526
'size': 6717,
24972527
'height': 225,
24982528
'width': 225,
2499-
'groupId': None,
2529+
'tags': [
2530+
'dog'
2531+
],
2532+
"annotations": [
2533+
{
2534+
"id": "YOUR_DATASET_OBJECT_ANNOTATION_ID",
2535+
"type": "bbox",
2536+
"title": "dog",
2537+
"value": "dog",
2538+
"points": [
2539+
0
2540+
],
2541+
"attributes": [
2542+
{
2543+
"value": "Scottish field",
2544+
"key": "kind",
2545+
"name": "Kind",
2546+
"type": "text"
2547+
}
2548+
],
2549+
"keypoints": [
2550+
{
2551+
"edges": [
2552+
"right_shoulder",
2553+
"left_shoulder"
2554+
],
2555+
"value": [
2556+
102.59,
2557+
23.04,
2558+
1
2559+
],
2560+
"key": "head",
2561+
"name": ""
2562+
}
2563+
],
2564+
"rotation": 0,
2565+
"color": "#FF0000",
2566+
"confidenceScore": -1
2567+
}
2568+
],
25002569
'createdAt': '2022-10-30T08:32:20.748Z',
25012570
'updatedAt': '2022-10-30T08:32:20.748Z'
25022571
}
@@ -2519,20 +2588,28 @@ Success response is the same as when created.
25192588
Get all dataset object in the dataset. (Up to 1000 tasks)
25202589

25212590
```python
2522-
dataset_objects = client.get_dataset_objects(dataset_version_id="YOUR_DATASET_VERSION_ID")
2591+
dataset_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
25232592
```
25242593

25252594
The success response is the same as when created, but it is an array.
25262595

2527-
You can filter by keywords.
2596+
You can filter by version and tags.
25282597

25292598
```python
25302599
dataset_objects = client.get_dataset_objects(
2531-
dataset_version_id="YOUR_DATASET_VERSION_ID", keyword="dog"
2600+
dataset="YOUR_DATASET_NAME",
2601+
version="latest", # default is "latest"
2602+
tags=["cat"],
25322603
)
25332604
```
25342605

2535-
If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get-tasks).
2606+
### Delete Dataset Object
2607+
2608+
Delete a single dataset object.
2609+
2610+
```python
2611+
client.delete_dataset_object(dataset_object_id="YOUR_DATASET_OBJECT_ID")
2612+
```
25362613

25372614
## Converter
25382615

examples/create_dataset_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
client = fastlabel.Client()
66

77
dataset_object = client.create_dataset_object(
8-
dataset_version_id="YOUR_DATASET_VERSION_ID",
8+
dataset="YOUR_DATASET_NAME",
99
name="NAME",
1010
file_path="FILE_PATH",
1111
)

examples/delete_dataset_object.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import fastlabel
2+
3+
client = fastlabel.Client()
4+
5+
client.delete_dataset_object(dataset_object_id="YOUR_DATASET_OBJECT_ID")

examples/get_dataset_objects.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44

55
client = fastlabel.Client()
66

7-
dataset_objects = client.get_dataset_objects(
8-
dataset_version_id="YOUR_DATASET_VERSION_ID"
9-
)
7+
dataset_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
108
pprint(dataset_objects)

fastlabel/__init__.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,58 +3910,65 @@ def find_dataset_object(self, dataset_object_id: str) -> dict:
39103910

39113911
def get_dataset_objects(
39123912
self,
3913-
dataset_version_id: str,
3914-
keyword: str = None,
3915-
offset: int = None,
3916-
limit: int = 100,
3913+
dataset: str,
3914+
version: str = None,
3915+
tags: List[str] = [],
39173916
) -> list:
39183917
"""
39193918
Returns a list of dataset objects.
39203919
3921-
Returns up to 1000 at a time, to get more, set offset as the starting position
3922-
to fetch.
3923-
3924-
dataset_version_id is dataset object in dataset version (Required).
3925-
keyword are search terms in the dataset object name (Optional).
3926-
offset is the starting position number to fetch (Optional).
3927-
limit is the max number to fetch (Optional).
3920+
dataset is dataset name (Required).
3921+
version is dataset version (Optional).
3922+
tags is a list of tag (Optional).
39283923
"""
3929-
if limit > 1000:
3930-
raise FastLabelInvalidException(
3931-
"Limit must be less than or equal to 1000.", 422
3932-
)
39333924
endpoint = "dataset-objects"
3934-
params = {"datasetVersionId": dataset_version_id}
3935-
if keyword:
3936-
params["keyword"] = keyword
3937-
if offset:
3938-
params["offset"] = offset
3939-
if limit:
3940-
params["limit"] = limit
3925+
params = {"dataset": dataset}
3926+
if version:
3927+
params["version"] = version
3928+
if tags:
3929+
params["tags"] = tags
39413930
return self.api.get_request(endpoint, params=params)
39423931

39433932
def create_dataset_object(
3944-
self, dataset_version_id: str, name: str, file_path: str
3933+
self,
3934+
dataset: str,
3935+
name: str,
3936+
file_path: str,
3937+
tags: List[str] = [],
3938+
annotations: List[dict] = [],
39453939
) -> dict:
39463940
"""
39473941
Create a dataset object.
39483942
3949-
dataset_version_id is dataset object in dataset version (Required).
3943+
dataset is dataset name (Required).
39503944
name is a unique identifier of dataset object in your dataset (Required).
39513945
file_path is a path to data. (Required).
3946+
tags is a list of tag (Optional).
3947+
annotations is a list of annotation (Optional).
39523948
"""
39533949
endpoint = "dataset-objects"
39543950
if not utils.is_object_supported_size(file_path):
39553951
raise FastLabelInvalidException(
39563952
"Supported object size is under 250 MB.", 422
39573953
)
39583954
payload = {
3959-
"datasetVersionId": dataset_version_id,
3955+
"dataset": dataset,
39603956
"name": name,
3961-
"file": utils.base64_encode(file_path),
3957+
"filePath": utils.base64_encode(file_path),
39623958
}
3959+
if tags:
3960+
payload["tags"] = tags
3961+
if annotations:
3962+
payload["annotations"] = annotations
39633963
return self.api.post_request(endpoint, payload=payload)
39643964

3965+
def delete_dataset_object(self, dataset_object_id: str) -> None:
3966+
"""
3967+
Delete a dataset object.
3968+
"""
3969+
endpoint = "dataset-objects/" + dataset_object_id
3970+
self.api.delete_request(endpoint)
3971+
39653972
def update_aws_s3_storage(
39663973
self, project: str, bucket_name: str, bucket_region: str, prefix: str = None
39673974
) -> str:

fastlabel/api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
2-
import requests
32
from typing import Union
43

4+
import requests
5+
56
from .exceptions import FastLabelException, FastLabelInvalidException
67

78

89
class Api:
9-
1010
base_url = "https://api.fastlabel.ai/v1/"
1111
access_token = None
1212

@@ -124,6 +124,5 @@ def upload_zipfile(
124124
url: str,
125125
file_path: str,
126126
):
127-
files = {'file': open(file_path, 'rb')}
127+
files = {"file": open(file_path, "rb")}
128128
return requests.put(url, files=files)
129-

0 commit comments

Comments
 (0)