From fa449e48af9ce37b27539e6d899ea7f6ef6e72fd Mon Sep 17 00:00:00 2001 From: ueta-eisuke Date: Mon, 2 Aug 2021 22:56:35 +0900 Subject: [PATCH 1/2] fix readme --- examples/donwload_images.py | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/donwload_images.py diff --git a/examples/donwload_images.py b/examples/donwload_images.py new file mode 100644 index 0000000..5afb6c2 --- /dev/null +++ b/examples/donwload_images.py @@ -0,0 +1,42 @@ +import fastlabel +import os +import time +import urllib.request +from multiprocessing import Pool, cpu_count + + +client = fastlabel.Client() +IMAGE_DIR = "images" +PROJECT_SLUG = "food-image-collection" + +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) \ No newline at end of file From 1d5a10fa67560dbb2b657d7104f8df6852d78cd3 Mon Sep 17 00:00:00 2001 From: ueta-eisuke Date: Mon, 2 Aug 2021 22:57:36 +0900 Subject: [PATCH 2/2] change project slug --- examples/donwload_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/donwload_images.py b/examples/donwload_images.py index 5afb6c2..3c4797f 100644 --- a/examples/donwload_images.py +++ b/examples/donwload_images.py @@ -7,7 +7,7 @@ client = fastlabel.Client() IMAGE_DIR = "images" -PROJECT_SLUG = "food-image-collection" +PROJECT_SLUG = "YOUR_PROJECT_SLUG" def get_all_tasks() -> list: # Iterate pages until new tasks are empty.