glenn-jocher commited on
Commit
6306091
1 Parent(s): 9ac7d38

Update `check_datasets()` for dynamic unzip path (#3732)

Browse files
Files changed (1) hide show
  1. utils/general.py +4 -3
utils/general.py CHANGED
@@ -223,16 +223,17 @@ def check_file(file):
223
  def check_dataset(data, autodownload=True):
224
  # Download dataset if not found locally
225
  val, s = data.get('val'), data.get('download')
226
- if val and len(val):
 
227
  val = [Path(x).resolve() for x in (val if isinstance(val, list) else [val])] # val path
228
  if not all(x.exists() for x in val):
229
  print('\nWARNING: Dataset not found, nonexistent paths: %s' % [str(x) for x in val if not x.exists()])
230
- if s and len(s) and autodownload: # download script
231
  if s.startswith('http') and s.endswith('.zip'): # URL
232
  f = Path(s).name # filename
233
  print(f'Downloading {s} ...')
234
  torch.hub.download_url_to_file(s, f)
235
- r = os.system(f'unzip -q {f} -d ../ && rm {f}') # unzip
236
  elif s.startswith('bash '): # bash script
237
  print(f'Running {s} ...')
238
  r = os.system(s)
 
223
  def check_dataset(data, autodownload=True):
224
  # Download dataset if not found locally
225
  val, s = data.get('val'), data.get('download')
226
+ if val:
227
+ root = Path(val).parts[0] + os.sep # unzip directory i.e. '../'
228
  val = [Path(x).resolve() for x in (val if isinstance(val, list) else [val])] # val path
229
  if not all(x.exists() for x in val):
230
  print('\nWARNING: Dataset not found, nonexistent paths: %s' % [str(x) for x in val if not x.exists()])
231
+ if s and autodownload: # download script
232
  if s.startswith('http') and s.endswith('.zip'): # URL
233
  f = Path(s).name # filename
234
  print(f'Downloading {s} ...')
235
  torch.hub.download_url_to_file(s, f)
236
+ r = os.system(f'unzip -q {f} -d {root} && rm {f}') # unzip
237
  elif s.startswith('bash '): # bash script
238
  print(f'Running {s} ...')
239
  r = os.system(s)