-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from fastlabel/feature/resurrection-examples
resurrect examples
- Loading branch information
Showing
12 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |