Update download() for tar.gz files (#2919)
* Update download() for tar.gz files * Update general.py
This commit is contained in:
parent
1b1ab4cca2
commit
45632b2704
|
|
@ -184,14 +184,19 @@ def check_dataset(dict):
|
||||||
|
|
||||||
|
|
||||||
def download(url, dir='.', multi_thread=False):
|
def download(url, dir='.', multi_thread=False):
|
||||||
# Multi-threaded file download function
|
# Multi-threaded file download and unzip function
|
||||||
def download_one(url, dir):
|
def download_one(url, dir):
|
||||||
# Download 1 file
|
# Download 1 file
|
||||||
f = dir / Path(url).name # filename
|
f = dir / Path(url).name # filename
|
||||||
print(f'Downloading {url} to {f}...')
|
if not f.exists():
|
||||||
torch.hub.download_url_to_file(url, f, progress=True) # download
|
print(f'Downloading {url} to {f}...')
|
||||||
if f.suffix == '.zip':
|
torch.hub.download_url_to_file(url, f, progress=True) # download
|
||||||
os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite
|
if f.suffix in ('.zip', '.gz'):
|
||||||
|
print(f'Unzipping {f}...')
|
||||||
|
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 = Path(dir)
|
||||||
dir.mkdir(parents=True, exist_ok=True) # make directory
|
dir.mkdir(parents=True, exist_ok=True) # make directory
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue