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

+1 -1
View File
@@ -1004,7 +1004,7 @@ class HUBDatasetStats():
self.hub_dir = Path(data['path'] + '-hub')
self.im_dir = self.hub_dir / 'images'
self.im_dir.mkdir(parents=True, exist_ok=True) # makes /images
self.stats = {'nc': data['nc'], 'names': data['names']} # statistics dictionary
self.stats = {'nc': data['nc'], 'names': list(data['names'].values())} # statistics dictionary
self.data = data
@staticmethod
+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 '.'