Skip to content

Commit b231538

Browse files
Merge branch 'main' into add-dataset-training
2 parents d8efed1 + 0d44f1d commit b231538

15 files changed

+290
-36
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,21 @@ dataset_object = client.find_dataset_object(
25832583
object_name="brushwood_dog.jpg"
25842584
)
25852585
```
2586-
2586+
You can find a object of specified revision by version or revision_id.
2587+
```python
2588+
dataset_object = client.find_dataset_object(
2589+
dataset_id="YOUR_DATASET_ID",
2590+
object_name="brushwood_dog.jpg",
2591+
version="YOUR_VERSION_NAME" # default is "latest"
2592+
)
2593+
```
2594+
```python
2595+
dataset_object = client.find_dataset_object(
2596+
dataset_id="YOUR_DATASET_ID",
2597+
object_name="brushwood_dog.jpg",
2598+
revision_id="YOUR_REVISION_ID" # 8 characters or more
2599+
)
2600+
```
25872601
Success response is the same as when created.
25882602

25892603
### Get Dataset Object
@@ -2596,7 +2610,7 @@ dataset_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
25962610

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

2599-
You can filter by version and tags.
2613+
You can filter by version or revision_id and tags.
26002614

26012615
```python
26022616
dataset_objects = client.get_dataset_objects(
@@ -2605,7 +2619,12 @@ dataset_objects = client.get_dataset_objects(
26052619
tags=["cat"],
26062620
)
26072621
```
2608-
2622+
```python
2623+
dataset_objects = client.get_dataset_objects(
2624+
dataset="YOUR_DATASET_NAME",
2625+
revision_id="YOUR_REVISION_ID" # 8 characters or more
2626+
)
2627+
```
26092628
### Download Dataset Objects
26102629

26112630
Download dataset objects in the dataset to specific directories.

examples/create_dataset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pprint import pprint
2+
3+
import fastlabel
4+
5+
client = fastlabel.Client()
6+
7+
dataset = client.create_dataset(name="object-detection", license="The MIT License")
8+
9+
pprint(dataset)

examples/create_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.create_dataset_object(
8+
dataset="YOUR_DATASET_NAME",
9+
name="NAME",
10+
file_path="FILE_PATH",
11+
)
12+
pprint(dataset_object)

examples/create_image_task.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pprint import pprint
2+
3+
import fastlabel
4+
5+
# Initialize client
6+
client = fastlabel.Client()
7+
8+
project = "YOUR_PROJECT_SLUG"
9+
name = "YOUR_DATA_NAME"
10+
file_path = "YOUR_DATA_FILE_PATH" # e.g.) ./cat.jpg
11+
annotations = [
12+
{
13+
"type": "bbox",
14+
"value": "cat",
15+
"attributes": [{"key": "kind", "value": "Scottish field"}],
16+
"points": [
17+
100, # top-left x
18+
100, # top-left y
19+
200, # bottom-right x
20+
200, # bottom-right y
21+
],
22+
}
23+
]
24+
25+
task_id = client.create_image_task(
26+
project=project, name=name, file_path=file_path, annotations=annotations
27+
)
28+
pprint(task_id)

examples/delete_dataset.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(dataset_id="YOUR_DATASET_ID")

examples/delete_dataset_object.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fastlabel
2+
3+
client = fastlabel.Client()
4+
5+
client.delete_dataset_object(
6+
dataset_id="YOUR_DATASET_OBJECT_ID", object_name="YOUR_OBJECT_NAME"
7+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fastlabel
2+
3+
client = fastlabel.Client()
4+
5+
client.download_dataset_objects(
6+
dataset="object-detection", path="./downloads", types=["train", "valid"]
7+
)

examples/download_images.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import time
3+
import urllib.request
4+
from multiprocessing import Pool, cpu_count
5+
6+
import fastlabel
7+
8+
client = fastlabel.Client()
9+
IMAGE_DIR = "images"
10+
PROJECT_SLUG = "YOUR_PROJECT_SLUG"
11+
12+
13+
def get_all_tasks() -> list:
14+
# Iterate pages until new tasks are empty.
15+
all_tasks = []
16+
offset = None
17+
while True:
18+
time.sleep(1)
19+
20+
tasks = client.get_image_classification_tasks(
21+
project=PROJECT_SLUG, limit=1000, offset=offset
22+
)
23+
all_tasks.extend(tasks)
24+
25+
if len(tasks) > 0:
26+
offset = len(all_tasks) # Set the offset
27+
else:
28+
break
29+
30+
return all_tasks
31+
32+
33+
def download_image(task: dict):
34+
urllib.request.urlretrieve(task["url"], os.path.join(IMAGE_DIR, task["name"]))
35+
36+
37+
if __name__ == "__main__":
38+
os.makedirs(IMAGE_DIR, exist_ok=True)
39+
40+
tasks = get_all_tasks()
41+
with Pool(cpu_count()) as p:
42+
p.map(download_image, tasks)

examples/find_dataset.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pprint import pprint
2+
3+
import fastlabel
4+
5+
client = fastlabel.Client()
6+
7+
dataset = client.find_dataset(dataset_id="YOUR_DATASET_ID")
8+
pprint(dataset)

examples/find_dataset_object.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pprint import pprint
2+
3+
import fastlabel
4+
5+
client = fastlabel.Client()
6+
7+
dataset_object = client.find_dataset_object(
8+
dataset_id="YOUR_DATASET_OBJECT_ID", object_name="YOUR_OBJECT_NAME"
9+
)
10+
pprint(dataset_object)

0 commit comments

Comments
 (0)