glenn-jocher commited on
Commit
32b8738
·
unverified ·
1 Parent(s): 5f603a9

Update `check_file()` avoid repeat URL downloads (#5526)

Browse files
Files changed (1) hide show
  1. utils/general.py +6 -3
utils/general.py CHANGED
@@ -338,9 +338,12 @@ def check_file(file, suffix=''):
338
  elif file.startswith(('http:/', 'https:/')): # download
339
  url = str(Path(file)).replace(':/', '://') # Pathlib turns :// -> :/
340
  file = Path(urllib.parse.unquote(file).split('?')[0]).name # '%2F' to '/', split https://url.com/file.txt?auth
341
- print(f'Downloading {url} to {file}...')
342
- torch.hub.download_url_to_file(url, file)
343
- assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check
 
 
 
344
  return file
345
  else: # search
346
  files = []
 
338
  elif file.startswith(('http:/', 'https:/')): # download
339
  url = str(Path(file)).replace(':/', '://') # Pathlib turns :// -> :/
340
  file = Path(urllib.parse.unquote(file).split('?')[0]).name # '%2F' to '/', split https://url.com/file.txt?auth
341
+ if Path(file).is_file():
342
+ print(f'Found {url} locally at {file}') # file already exists
343
+ else:
344
+ print(f'Downloading {url} to {file}...')
345
+ torch.hub.download_url_to_file(url, file)
346
+ assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check
347
  return file
348
  else: # search
349
  files = []