Quellcode durchsuchen

Update `dataset_stats()` for HUB (#3536)

* Update `dataset_stats()` for HUB 

Cleanup of b6fdd2e

* autodownload flag

* Update general.py

* cleanup
modifyDataloader
Glenn Jocher GitHub vor 3 Jahren
Ursprung
Commit
1b5edb6f8e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 8 neuen und 9 gelöschten Zeilen
  1. +5
    -6
      utils/datasets.py
  2. +3
    -3
      utils/general.py

+ 5
- 6
utils/datasets.py Datei anzeigen

@@ -1086,18 +1086,17 @@ def verify_image_label(params):
return [None] * 4 + [nm, nf, ne, nc]


def dataset_stats(path='data/coco128.yaml', verbose=False):
def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False):
""" Return dataset statistics dictionary with images and instances counts per split per class
Usage: from utils.datasets import *; dataset_stats('data/coco128.yaml')
Usage: from utils.datasets import *; dataset_stats('coco128.yaml', verbose=True)
Arguments
path: Path to data.yaml
autodownload: Attempt to download dataset if not found locally
verbose: Print stats dictionary
"""
path = check_file(Path(path))
with open(path) as f:
with open(check_file(Path(path))) as f:
data = yaml.safe_load(f) # data dict
check_dataset(data) # download dataset if missing

check_dataset(data, autodownload) # download dataset if missing
nc = data['nc'] # number of classes
stats = {'nc': nc, 'names': data['names']} # statistics dictionary
for split in 'train', 'val', 'test':

+ 3
- 3
utils/general.py Datei anzeigen

@@ -220,14 +220,14 @@ def check_file(file):
return files[0] # return file


def check_dataset(dict):
def check_dataset(data, autodownload=True):
# Download dataset if not found locally
val, s = dict.get('val'), dict.get('download')
val, s = data.get('val'), data.get('download')
if val and len(val):
val = [Path(x).resolve() for x in (val if isinstance(val, list) else [val])] # val path
if not all(x.exists() for x in val):
print('\nWARNING: Dataset not found, nonexistent paths: %s' % [str(x) for x in val if not x.exists()])
if s and len(s): # download script
if s and len(s) and autodownload: # download script
if s.startswith('http') and s.endswith('.zip'): # URL
f = Path(s).name # filename
print(f'Downloading {s} ...')

Laden…
Abbrechen
Speichern