Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 83 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2476,11 +2476,41 @@ Create object in the dataset.
The types of objects that can be created are "image", "video", and "audio".
There are type-specific methods. but they can be used in the same way.

Created object are automatically assigned to the "latest" dataset version.

```python
dataset_object = client.create_dataset_object(
dataset_version_id="YOUR_DATASET_VERSION_ID",
dataset="YOUR_DATASET_NAME",
name="brushwood_dog.jpg",
file_path="./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'.
}
]
)
```

Expand All @@ -2495,7 +2525,46 @@ See API docs for details.
'size': 6717,
'height': 225,
'width': 225,
'groupId': None,
'tags': [
'dog'
],
"annotations": [
{
"id": "YOUR_DATASET_OBJECT_ANNOTATION_ID",
"type": "bbox",
"title": "dog",
"value": "dog",
"points": [
0
],
"attributes": [
{
"value": "Scottish field",
"key": "kind",
"name": "Kind",
"type": "text"
}
],
"keypoints": [
{
"edges": [
"right_shoulder",
"left_shoulder"
],
"value": [
102.59,
23.04,
1
],
"key": "head",
"name": "頭"
}
],
"rotation": 0,
"color": "#FF0000",
"confidenceScore": -1
}
],
'createdAt': '2022-10-30T08:32:20.748Z',
'updatedAt': '2022-10-30T08:32:20.748Z'
}
Expand All @@ -2518,20 +2587,28 @@ Success response is the same as when created.
Get all dataset object in the dataset. (Up to 1000 tasks)

```python
dataset_objects = client.get_dataset_objects(dataset_version_id="YOUR_DATASET_VERSION_ID")
dataset_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
```

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

You can filter by keywords.
You can filter by version and tags.

```python
dataset_objects = client.get_dataset_objects(
dataset_version_id="YOUR_DATASET_VERSION_ID", keyword="dog"
dataset="YOUR_DATASET_NAME",
version="latest", # default is "latest"
tags=["cat"],
)
```

If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get-tasks).
### Delete Dataset Object

Delete a single dataset object.

```python
client.delete_dataset_object(dataset_object_id="YOUR_DATASET_OBJECT_ID")
```

## Converter

Expand Down
2 changes: 1 addition & 1 deletion examples/create_dataset_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
client = fastlabel.Client()

dataset_object = client.create_dataset_object(
dataset_version_id="YOUR_DATASET_VERSION_ID",
dataset="YOUR_DATASET_NAME",
name="NAME",
file_path="FILE_PATH",
)
Expand Down
5 changes: 5 additions & 0 deletions examples/delete_dataset_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import fastlabel

client = fastlabel.Client()

client.delete_dataset_object(dataset_object_id="YOUR_DATASET_OBJECT_ID")
4 changes: 1 addition & 3 deletions examples/get_dataset_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

client = fastlabel.Client()

dataset_objects = client.get_dataset_objects(
dataset_version_id="YOUR_DATASET_VERSION_ID"
)
dataset_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
pprint(dataset_objects)
59 changes: 33 additions & 26 deletions fastlabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3907,58 +3907,65 @@ def find_dataset_object(self, dataset_object_id: str) -> dict:

def get_dataset_objects(
self,
dataset_version_id: str,
keyword: str = None,
offset: int = None,
limit: int = 100,
dataset: str,
version: str = None,
tags: List[str] = [],
) -> list:
"""
Returns a list of dataset objects.

Returns up to 1000 at a time, to get more, set offset as the starting position
to fetch.

dataset_version_id is dataset object in dataset version (Required).
keyword are search terms in the dataset object name (Optional).
offset is the starting position number to fetch (Optional).
limit is the max number to fetch (Optional).
dataset is dataset name (Required).
version is dataset version (Optional).
tags is a list of tag (Optional).
"""
if limit > 1000:
raise FastLabelInvalidException(
"Limit must be less than or equal to 1000.", 422
)
endpoint = "dataset-objects"
params = {"datasetVersionId": dataset_version_id}
if keyword:
params["keyword"] = keyword
if offset:
params["offset"] = offset
if limit:
params["limit"] = limit
params = {"dataset": dataset}
if version:
params["version"] = version
if tags:
params["tags"] = tags
return self.api.get_request(endpoint, params=params)

def create_dataset_object(
self, dataset_version_id: str, name: str, file_path: str
self,
dataset: str,
name: str,
file_path: str,
tags: List[str] = [],
annotations: List[dict] = [],
) -> dict:
"""
Create a dataset object.

dataset_version_id is dataset object in dataset version (Required).
dataset is dataset name (Required).
name is a unique identifier of dataset object in your dataset (Required).
file_path is a path to data. (Required).
tags is a list of tag (Optional).
annotations is a list of annotation (Optional).
"""
endpoint = "dataset-objects"
if not utils.is_object_supported_size(file_path):
raise FastLabelInvalidException(
"Supported object size is under 250 MB.", 422
)
payload = {
"datasetVersionId": dataset_version_id,
"dataset": dataset,
"name": name,
"file": utils.base64_encode(file_path),
"filePath": utils.base64_encode(file_path),
}
if tags:
payload["tags"] = tags
if annotations:
payload["annotations"] = annotations
return self.api.post_request(endpoint, payload=payload)

def delete_dataset_object(self, dataset_object_id: str) -> None:
"""
Delete a dataset object.
"""
endpoint = "dataset-objects/" + dataset_object_id
self.api.delete_request(endpoint)

def update_aws_s3_storage(
self, project: str, bucket_name: str, bucket_region: str, prefix: str = None
) -> str:
Expand Down
7 changes: 3 additions & 4 deletions fastlabel/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import requests
from typing import Union

import requests

from .exceptions import FastLabelException, FastLabelInvalidException


class Api:

base_url = "https://api.fastlabel.ai/v1/"
access_token = None

Expand Down Expand Up @@ -124,6 +124,5 @@ def upload_zipfile(
url: str,
file_path: str,
):
files = {'file': open(file_path, 'rb')}
files = {"file": open(file_path, "rb")}
return requests.put(url, files=files)

Loading