Skip to content

Commit

Permalink
Update download() for tar.gz files (ultralytics#2919)
Browse files Browse the repository at this point in the history
* Update download() for tar.gz files

* Update general.py

(cherry picked from commit 45632b2)
  • Loading branch information
glenn-jocher authored and Lechtr committed Apr 25, 2021
1 parent e09366f commit d782e5f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,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 f.suffix == '.zip':
os.system(f'unzip -qo {f} -d {dir} && rm {f}') # unzip -quiet -overwrite
if not f.exists():
print(f'Downloading {url} to {f}...')
torch.hub.download_url_to_file(url, f, progress=True) # download
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.mkdir(parents=True, exist_ok=True) # make directory
Expand Down

0 comments on commit d782e5f

Please sign in to comment.