Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from pycocotools.coco import COCO
from tqdm import tqdm
import os
import multiprocessing
from joblib import Parallel, delayed

anns_path = './annotations/annotations.json'
dest_path = './images/'



def try_download(source: str, dest: str, name: str):
print(f'downloading {source}')
r = requests.get(source, allow_redirects=True)
if r.ok:
with open(f'{dest}{name}', 'wb') as f:
Expand All @@ -25,9 +28,13 @@ def download(img: dict, dest_path: str):
def main():
dataset = COCO(anns_path)

for img in tqdm(dataset.imgs.values()):
download(img, dest_path)
download_pool = multiprocessing.Pool()

num_cores = multiprocessing.cpu_count()
nimgs = len(tqdm(dataset.imgs.values()))
inputs = tqdm(dataset.imgs.values())

processed_list = Parallel(n_jobs=num_cores)(delayed(download)(img, dest_path) for img in inputs)

if __name__ == '__main__':
main()
main()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
requests
pycocotools
tqdm
multiprocessing
joblib