Skip to content

Commit 149af98

Browse files
authored
Merge pull request #195 from fastlabel/feature/resurrection-examples
resurrect examples
2 parents 2c0f782 + babf167 commit 149af98

12 files changed

+152
-0
lines changed

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)

examples/get_dataset_objects.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_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
8+
pprint(dataset_objects)

0 commit comments

Comments
 (0)