glenn-jocher commited on
Commit
45632b2
·
unverified ·
1 Parent(s): 1b1ab4c

Update download() for tar.gz files (#2919)

Browse files

* Update download() for tar.gz files

* Update general.py

Files changed (1) hide show
  1. utils/general.py +10 -5
utils/general.py CHANGED
@@ -184,14 +184,19 @@ def check_dataset(dict):
184
 
185
 
186
  def download(url, dir='.', multi_thread=False):
187
- # Multi-threaded file download function
188
  def download_one(url, dir):
189
  # Download 1 file
190
  f = dir / Path(url).name # filename
191
- print(f'Downloading {url} to {f}...')
192
- torch.hub.download_url_to_file(url, f, progress=True) # download
193
- if f.suffix == '.zip':
194
- os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite
 
 
 
 
 
195
 
196
  dir = Path(dir)
197
  dir.mkdir(parents=True, exist_ok=True) # make directory
 
184
 
185
 
186
  def download(url, dir='.', multi_thread=False):
187
+ # Multi-threaded file download and unzip function
188
  def download_one(url, dir):
189
  # Download 1 file
190
  f = dir / Path(url).name # filename
191
+ if not f.exists():
192
+ print(f'Downloading {url} to {f}...')
193
+ torch.hub.download_url_to_file(url, f, progress=True) # download
194
+ if f.suffix in ('.zip', '.gz'):
195
+ print(f'Unzipping {f}...')
196
+ if f.suffix == '.zip':
197
+ os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite
198
+ elif f.suffix == '.gz':
199
+ os.system(f'tar xfz {f} --directory {f.parent} && rm {f}') # unzip
200
 
201
  dir = Path(dir)
202
  dir.mkdir(parents=True, exist_ok=True) # make directory