Skip to content

Commit

Permalink
Merge pull request #195 from fastlabel/feature/resurrection-examples
Browse files Browse the repository at this point in the history
resurrect examples
  • Loading branch information
anegawa-j authored Dec 8, 2023
2 parents 2c0f782 + babf167 commit 149af98
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/create_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

dataset = client.create_dataset(name="object-detection", license="The MIT License")

pprint(dataset)
12 changes: 12 additions & 0 deletions examples/create_dataset_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

dataset_object = client.create_dataset_object(
dataset="YOUR_DATASET_NAME",
name="NAME",
file_path="FILE_PATH",
)
pprint(dataset_object)
28 changes: 28 additions & 0 deletions examples/create_image_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pprint import pprint

import fastlabel

# Initialize client
client = fastlabel.Client()

project = "YOUR_PROJECT_SLUG"
name = "YOUR_DATA_NAME"
file_path = "YOUR_DATA_FILE_PATH" # e.g.) ./cat.jpg
annotations = [
{
"type": "bbox",
"value": "cat",
"attributes": [{"key": "kind", "value": "Scottish field"}],
"points": [
100, # top-left x
100, # top-left y
200, # bottom-right x
200, # bottom-right y
],
}
]

task_id = client.create_image_task(
project=project, name=name, file_path=file_path, annotations=annotations
)
pprint(task_id)
5 changes: 5 additions & 0 deletions examples/delete_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import fastlabel

client = fastlabel.Client()

client.delete_dataset(dataset_id="YOUR_DATASET_ID")
7 changes: 7 additions & 0 deletions examples/delete_dataset_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fastlabel

client = fastlabel.Client()

client.delete_dataset_object(
dataset_id="YOUR_DATASET_OBJECT_ID", object_name="YOUR_OBJECT_NAME"
)
7 changes: 7 additions & 0 deletions examples/download_dataset_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fastlabel

client = fastlabel.Client()

client.download_dataset_objects(
dataset="object-detection", path="./downloads", types=["train", "valid"]
)
42 changes: 42 additions & 0 deletions examples/download_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import time
import urllib.request
from multiprocessing import Pool, cpu_count

import fastlabel

client = fastlabel.Client()
IMAGE_DIR = "images"
PROJECT_SLUG = "YOUR_PROJECT_SLUG"


def get_all_tasks() -> list:
# Iterate pages until new tasks are empty.
all_tasks = []
offset = None
while True:
time.sleep(1)

tasks = client.get_image_classification_tasks(
project=PROJECT_SLUG, limit=1000, offset=offset
)
all_tasks.extend(tasks)

if len(tasks) > 0:
offset = len(all_tasks) # Set the offset
else:
break

return all_tasks


def download_image(task: dict):
urllib.request.urlretrieve(task["url"], os.path.join(IMAGE_DIR, task["name"]))


if __name__ == "__main__":
os.makedirs(IMAGE_DIR, exist_ok=True)

tasks = get_all_tasks()
with Pool(cpu_count()) as p:
p.map(download_image, tasks)
8 changes: 8 additions & 0 deletions examples/find_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

dataset = client.find_dataset(dataset_id="YOUR_DATASET_ID")
pprint(dataset)
10 changes: 10 additions & 0 deletions examples/find_dataset_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

dataset_object = client.find_dataset_object(
dataset_id="YOUR_DATASET_OBJECT_ID", object_name="YOUR_OBJECT_NAME"
)
pprint(dataset_object)
8 changes: 8 additions & 0 deletions examples/get_dataset_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

dataset_objects = client.get_dataset_objects(dataset="YOUR_DATASET_NAME")
pprint(dataset_objects)
8 changes: 8 additions & 0 deletions examples/get_datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

datasets = client.get_datasets()
pprint(datasets)
8 changes: 8 additions & 0 deletions examples/update_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pprint import pprint

import fastlabel

client = fastlabel.Client()

dataset = client.update_dataset(dataset_id="YOUR_DATASET_ID", name="object-detection")
pprint(dataset)

0 comments on commit 149af98

Please sign in to comment.