Add `data/utils.py` to tests (#4363)

single_channel
Glenn Jocher 1 year ago committed by GitHub
parent 834f94f899
commit 4093c1fd64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

@ -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}"

@ -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):

Loading…
Cancel
Save