Update dataset names from array to dictionary (#9000)

* Migrate dataset names to dictionary

* fix check

* backwards compat

* predict fix

* val fix

* Keep dataset stats behavior identical

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Glenn Jocher authored and GitHub committed 2022-08-17 17:52:53 +02:00
1 parent e8f24d5748
commit e83b422a69
15 files changed
+1646 -227

No files matched your search

+4 -4
View File
@@ -481,11 +481,11 @@ def check_dataset(data, autodownload=True):
data = yaml.safe_load(f) # dictionary
# Checks
for k in 'train', 'val', 'nc':
for k in 'train', 'val', 'names':
assert k in data, f"data.yaml '{k}:' field missing ❌"
if 'names' not in data:
LOGGER.warning("data.yaml 'names:' field missing ⚠️, assigning default names 'class0', 'class1', etc.")
data['names'] = [f'class{i}' for i in range(data['nc'])] # default names
if isinstance(data['names'], (list, tuple)): # old array format
data['names'] = dict(enumerate(data['names'])) # convert to dict
data['nc'] = len(data['names'])
# Resolve paths
path = Path(extract_dir or data.get('path') or '') # optional 'path' default to '.'