diff --git a/tests/test_python.py b/tests/test_python.py index 561b832852..a441a55bb3 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -1,4 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license + +import shutil from pathlib import Path import cv2 @@ -224,20 +226,22 @@ def test_results(): def test_data_utils(): # Test functions in ultralytics/data/utils.py - from ultralytics.data.utils import autosplit, zip_directory + from ultralytics.data.utils import HUBDatasetStats, autosplit, zip_directory + from ultralytics.utils.downloads import download # from ultralytics.utils.files import WorkingDirectory # with WorkingDirectory(ROOT.parent / 'tests'): - autosplit() - zip_directory(ROOT / 'assets') # zip - Path(ROOT / 'assets.zip').unlink() # delete zip - - # from ultralytics.data.utils import HUBDatasetStats - # from ultralytics.utils.downloads import download - # Path('coco8.zip').unlink(missing_ok=True) - # download('https://github.com/ultralytics/hub/raw/master/example_datasets/coco8.zip', unzip=False) - # shutil.move('coco8.zip', 'tests') - # stats = HUBDatasetStats('tests/coco8.zip', task='detect') - # stats.get_json(save=False) - # stats.process_images() + Path('tests/coco8.zip').unlink(missing_ok=True) + Path('coco8.zip').unlink(missing_ok=True) + download('https://github.com/ultralytics/hub/raw/master/example_datasets/coco8.zip', unzip=False) + shutil.move('coco8.zip', 'tests') + shutil.rmtree('tests/coco8', ignore_errors=True) + stats = HUBDatasetStats('tests/coco8.zip', task='detect') + stats.get_json(save=False) + stats.process_images() + + autosplit('tests/coco8') + zip_directory('tests/coco8/images/val') # zip + shutil.rmtree('tests/coco8', ignore_errors=True) + shutil.rmtree('tests/coco8-hub', ignore_errors=True) diff --git a/ultralytics/data/utils.py b/ultralytics/data/utils.py index 42fdd8e639..52ce9c4783 100644 --- a/ultralytics/data/utils.py +++ b/ultralytics/data/utils.py @@ -364,8 +364,9 @@ class HUBDatasetStats: def __init__(self, path='coco128.yaml', task='detect', autodownload=False): """Initialize class.""" + path = Path(path).resolve() LOGGER.info(f'Starting HUB dataset checks for {path}....') - zipped, data_dir, yaml_path = self._unzip(Path(path)) + zipped, data_dir, yaml_path = self._unzip(path) try: # data = yaml_load(check_yaml(yaml_path)) # data dict data = check_det_dataset(yaml_path, autodownload) # data dict @@ -385,7 +386,7 @@ class HUBDatasetStats: def _find_yaml(dir): """Return data.yaml file.""" files = list(dir.glob('*.yaml')) or list(dir.rglob('*.yaml')) # try root level first and then recursive - assert files, f'No *.yaml file found in {dir.resolve()}' + assert files, f"No *.yaml file found in '{dir.resolve()}'" if len(files) > 1: files = [f for f in files if f.stem == dir.stem] # prefer *.yaml files that match dir name assert len(files) == 1, f"Expected 1 *.yaml file in '{dir.resolve()}', but found {len(files)}.\n{files}" diff --git a/ultralytics/utils/downloads.py b/ultralytics/utils/downloads.py index 5672043b7d..44495af6cd 100644 --- a/ultralytics/utils/downloads.py +++ b/ultralytics/utils/downloads.py @@ -125,12 +125,12 @@ def unzip_file(file, path=None, exclude=('.DS_Store', '__MACOSX'), exist_ok=Fals if extract_path.exists() and any(extract_path.iterdir()) and not exist_ok: # If it exists and is not empty, return the path without unzipping LOGGER.info(f'Skipping {file} unzip (already unzipped)') - return path + return extract_path for f in tqdm(files, desc=f'Unzipping {file} to {Path(path).resolve()}...', unit='file', disable=not progress): zipObj.extract(f, path=path) - return path # return unzip dir + return extract_path # return unzip dir def check_disk_space(url='https://ultralytics.com/assets/coco128.zip', sf=1.5, hard=True):