mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 21:44:22 +08:00
Add data/utils.py
to tests (#4363)
This commit is contained in:
parent
834f94f899
commit
4093c1fd64
@ -1,4 +1,6 @@
|
|||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||||
|
|
||||||
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@ -224,20 +226,22 @@ def test_results():
|
|||||||
|
|
||||||
def test_data_utils():
|
def test_data_utils():
|
||||||
# Test functions in ultralytics/data/utils.py
|
# 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
|
# from ultralytics.utils.files import WorkingDirectory
|
||||||
# with WorkingDirectory(ROOT.parent / 'tests'):
|
# with WorkingDirectory(ROOT.parent / 'tests'):
|
||||||
|
|
||||||
autosplit()
|
Path('tests/coco8.zip').unlink(missing_ok=True)
|
||||||
zip_directory(ROOT / 'assets') # zip
|
Path('coco8.zip').unlink(missing_ok=True)
|
||||||
Path(ROOT / 'assets.zip').unlink() # delete zip
|
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()
|
||||||
|
|
||||||
# from ultralytics.data.utils import HUBDatasetStats
|
autosplit('tests/coco8')
|
||||||
# from ultralytics.utils.downloads import download
|
zip_directory('tests/coco8/images/val') # zip
|
||||||
# Path('coco8.zip').unlink(missing_ok=True)
|
shutil.rmtree('tests/coco8', ignore_errors=True)
|
||||||
# download('https://github.com/ultralytics/hub/raw/master/example_datasets/coco8.zip', unzip=False)
|
shutil.rmtree('tests/coco8-hub', ignore_errors=True)
|
||||||
# shutil.move('coco8.zip', 'tests')
|
|
||||||
# stats = HUBDatasetStats('tests/coco8.zip', task='detect')
|
|
||||||
# stats.get_json(save=False)
|
|
||||||
# stats.process_images()
|
|
||||||
|
@ -364,8 +364,9 @@ class HUBDatasetStats:
|
|||||||
|
|
||||||
def __init__(self, path='coco128.yaml', task='detect', autodownload=False):
|
def __init__(self, path='coco128.yaml', task='detect', autodownload=False):
|
||||||
"""Initialize class."""
|
"""Initialize class."""
|
||||||
|
path = Path(path).resolve()
|
||||||
LOGGER.info(f'Starting HUB dataset checks for {path}....')
|
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:
|
try:
|
||||||
# data = yaml_load(check_yaml(yaml_path)) # data dict
|
# data = yaml_load(check_yaml(yaml_path)) # data dict
|
||||||
data = check_det_dataset(yaml_path, autodownload) # data dict
|
data = check_det_dataset(yaml_path, autodownload) # data dict
|
||||||
@ -385,7 +386,7 @@ class HUBDatasetStats:
|
|||||||
def _find_yaml(dir):
|
def _find_yaml(dir):
|
||||||
"""Return data.yaml file."""
|
"""Return data.yaml file."""
|
||||||
files = list(dir.glob('*.yaml')) or list(dir.rglob('*.yaml')) # try root level first and then recursive
|
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:
|
if len(files) > 1:
|
||||||
files = [f for f in files if f.stem == dir.stem] # prefer *.yaml files that match dir name
|
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}"
|
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 extract_path.exists() and any(extract_path.iterdir()) and not exist_ok:
|
||||||
# If it exists and is not empty, return the path without unzipping
|
# If it exists and is not empty, return the path without unzipping
|
||||||
LOGGER.info(f'Skipping {file} unzip (already unzipped)')
|
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):
|
for f in tqdm(files, desc=f'Unzipping {file} to {Path(path).resolve()}...', unit='file', disable=not progress):
|
||||||
zipObj.extract(f, path=path)
|
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):
|
def check_disk_space(url='https://ultralytics.com/assets/coco128.zip', sf=1.5, hard=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user