From 89762085a8941bb6298be7045233d1b2904d6aef Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 24 Apr 2021 15:47:05 +0200 Subject: [PATCH 1/2] Update download() for tar.gz files --- utils/general.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/utils/general.py b/utils/general.py index ba88759c2983..a66e3a9fd7a9 100755 --- a/utils/general.py +++ b/utils/general.py @@ -184,14 +184,19 @@ def check_dataset(dict): def download(url, dir='.', multi_thread=False): - # Multi-threaded file download function + # Multi-threaded file download and unzip function def download_one(url, dir): # Download 1 file f = dir / Path(url).name # filename - print(f'Downloading {url} to {f}...') - torch.hub.download_url_to_file(url, f, progress=True) # download + if not f.exists(): + print(f'Downloading {url} to {f}...') + torch.hub.download_url_to_file(url, f, progress=True) # download if f.suffix == '.zip': + print(f'Unzipping {f}...') os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite + elif f.suffix == '.gz': + print(f'Unzipping {f}...') + os.system(f'tar xfz {f} --directory {f.parent} && rm {f}') # unzip dir = Path(dir) dir.mkdir(parents=True, exist_ok=True) # make directory From ae193e5d6efbb8bd79d7d88c34b94aabd3fb4967 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 24 Apr 2021 15:50:11 +0200 Subject: [PATCH 2/2] Update general.py --- utils/general.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index a66e3a9fd7a9..8efeb5ea59cc 100755 --- a/utils/general.py +++ b/utils/general.py @@ -191,12 +191,12 @@ def download_one(url, dir): if not f.exists(): print(f'Downloading {url} to {f}...') torch.hub.download_url_to_file(url, f, progress=True) # download - if f.suffix == '.zip': + if f.suffix in ('.zip', '.gz'): print(f'Unzipping {f}...') - os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite - elif f.suffix == '.gz': - print(f'Unzipping {f}...') - os.system(f'tar xfz {f} --directory {f.parent} && rm {f}') # unzip + if f.suffix == '.zip': + os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite + elif f.suffix == '.gz': + os.system(f'tar xfz {f} --directory {f.parent} && rm {f}') # unzip dir = Path(dir) dir.mkdir(parents=True, exist_ok=True) # make directory