From 37eaffec7d7a8d82d24082392dd5dc95e56881d3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 1 May 2021 17:29:51 +0200 Subject: [PATCH] Curl update (#3004) * Curl update * Curl update --- data/scripts/get_objects365.py | 2 +- utils/general.py | 7 +++++-- utils/google_utils.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/data/scripts/get_objects365.py b/data/scripts/get_objects365.py index 307dfe0da599..d77b26d60691 100644 --- a/data/scripts/get_objects365.py +++ b/data/scripts/get_objects365.py @@ -22,7 +22,7 @@ # Download url = "https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/train/" download([url + 'zhiyuan_objv2_train.tar.gz'], dir=dir) # annotations json -download([url + f for f in [f'patch{i}.tar.gz' for i in range(51)]], dir=dir / 'images' / 'train', threads=8) +download([url + f for f in [f'patch{i}.tar.gz' for i in range(51)]], dir=dir / 'images' / 'train', curl=True, threads=8) # Labels coco = COCO(dir / 'zhiyuan_objv2_train.json') diff --git a/utils/general.py b/utils/general.py index 7e50a7333dea..0c5928d8d06f 100755 --- a/utils/general.py +++ b/utils/general.py @@ -183,14 +183,17 @@ def check_dataset(dict): raise Exception('Dataset not found.') -def download(url, dir='.', unzip=True, threads=1): +def download(url, dir='.', unzip=True, curl=False, threads=1): # Multi-threaded file download and unzip function def download_one(url, dir): # Download 1 file f = dir / Path(url).name # filename if not f.exists(): print(f'Downloading {url} to {f}...') - torch.hub.download_url_to_file(url, f, progress=True) # download + if curl: + os.system(f"curl -L '{url}' -o '{f}' --retry 9 -C -") # curl download, retry and resume on fail + else: + torch.hub.download_url_to_file(url, f, progress=True) # torch download if unzip and f.suffix in ('.zip', '.gz'): print(f'Unzipping {f}...') if f.suffix == '.zip': diff --git a/utils/google_utils.py b/utils/google_utils.py index 6a4660bad509..eae2d1b9ffcc 100644 --- a/utils/google_utils.py +++ b/utils/google_utils.py @@ -47,7 +47,7 @@ def attempt_download(file, repo='ultralytics/yolov5'): assert redundant, 'No secondary mirror' url = f'https://storage.googleapis.com/{repo}/ckpt/{name}' print(f'Downloading {url} to {file}...') - os.system(f'curl -L {url} -o {file}') # torch.hub.download_url_to_file(url, weights) + os.system(f"curl -L '{url}' -o '{file}' --retry 3 -C -") # curl download, retry and resume on fail finally: if not file.exists() or file.stat().st_size < 1E6: # check file.unlink(missing_ok=True) # remove partial downloads