Skip to content

Commit

Permalink
Resolve dataset paths (ultralytics#6489)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored Feb 1, 2022
1 parent 5a29551 commit c0f078c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,15 @@ def check_dataset(data, autodownload=True):
with open(data, errors='ignore') as f:
data = yaml.safe_load(f) # dictionary

# Parse yaml
path = extract_dir or Path(data.get('path') or '') # optional 'path' default to '.'
# Resolve paths
path = Path(extract_dir or data.get('path') or '') # optional 'path' default to '.'
if not path.is_absolute():
path = (ROOT / path).resolve()
for k in 'train', 'val', 'test':
if data.get(k): # prepend path
data[k] = str(path / data[k]) if isinstance(data[k], str) else [str(path / x) for x in data[k]]

# Parse yaml
assert 'nc' in data, "Dataset 'nc' key missing."
if 'names' not in data:
data['names'] = [f'class{i}' for i in range(data['nc'])] # assign class names if missing
Expand Down

0 comments on commit c0f078c

Please sign in to comment.