glenn-jocher commited on
Commit
39c17ce
1 Parent(s): a64a4c8

Fix `root` referenced before assignment (#4920)

Browse files

* Fix `root` referenced before assignment

Fix for bug introduced by #4919 discovered on VOC autodownload:
```
python train.py --data VOC.yaml
```

* Cleanup

Files changed (1) hide show
  1. utils/general.py +2 -2
utils/general.py CHANGED
@@ -352,11 +352,11 @@ def check_dataset(data, autodownload=True):
352
  if not all(x.exists() for x in val):
353
  print('\nWARNING: Dataset not found, nonexistent paths: %s' % [str(x) for x in val if not x.exists()])
354
  if s and autodownload: # download script
 
355
  if s.startswith('http') and s.endswith('.zip'): # URL
356
  f = Path(s).name # filename
357
  print(f'Downloading {s} to {f}...')
358
  torch.hub.download_url_to_file(s, f)
359
- root = path.parent if 'path' in data else '..' # unzip directory i.e. '../'
360
  Path(root).mkdir(parents=True, exist_ok=True) # create root
361
  ZipFile(f).extractall(path=root) # unzip
362
  Path(f).unlink() # remove zip
@@ -366,7 +366,7 @@ def check_dataset(data, autodownload=True):
366
  r = os.system(s)
367
  else: # python script
368
  r = exec(s, {'yaml': data}) # return None
369
- print(f"Dataset autodownload {f'success, saved to {root}' if r in (0, None) else 'failure'}")
370
  else:
371
  raise Exception('Dataset not found.')
372
 
 
352
  if not all(x.exists() for x in val):
353
  print('\nWARNING: Dataset not found, nonexistent paths: %s' % [str(x) for x in val if not x.exists()])
354
  if s and autodownload: # download script
355
+ root = path.parent if 'path' in data else '..' # unzip directory i.e. '../'
356
  if s.startswith('http') and s.endswith('.zip'): # URL
357
  f = Path(s).name # filename
358
  print(f'Downloading {s} to {f}...')
359
  torch.hub.download_url_to_file(s, f)
 
360
  Path(root).mkdir(parents=True, exist_ok=True) # create root
361
  ZipFile(f).extractall(path=root) # unzip
362
  Path(f).unlink() # remove zip
 
366
  r = os.system(s)
367
  else: # python script
368
  r = exec(s, {'yaml': data}) # return None
369
+ print(f"Dataset autodownload {f'success, saved to {root}' if r in (0, None) else 'failure'}\n")
370
  else:
371
  raise Exception('Dataset not found.')
372