File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ import fastlabel
2+ import os
3+ import time
4+ import urllib .request
5+ from multiprocessing import Pool , cpu_count
6+
7+
8+ client = fastlabel .Client ()
9+ IMAGE_DIR = "images"
10+ PROJECT_SLUG = "YOUR_PROJECT_SLUG"
11+
12+ def get_all_tasks () -> list :
13+ # Iterate pages until new tasks are empty.
14+ all_tasks = []
15+ offset = None
16+ while True :
17+ time .sleep (1 )
18+
19+ tasks = client .get_image_classification_tasks (
20+ project = PROJECT_SLUG ,
21+ limit = 1000 ,
22+ offset = offset
23+ )
24+ all_tasks .extend (tasks )
25+
26+ if len (tasks ) > 0 :
27+ offset = len (all_tasks ) # Set the offset
28+ else :
29+ break
30+
31+ return all_tasks
32+
33+ def download_image (task : dict ):
34+ urllib .request .urlretrieve (task ["url" ], os .path .join (IMAGE_DIR , task ["name" ]))
35+
36+ if __name__ == '__main__' :
37+
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 )
You can’t perform that action at this time.
0 commit comments