ultralytics 8.0.191 fix yolo checks for missing packages (#5179)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Muhammad Rizwan Munawar <62513924+RizwanMunawar@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2023-10-02 22:45:30 +02:00 committed by GitHub
parent 9aaa5d5ed0
commit 525c8b0294
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 110 additions and 74 deletions

View file

@ -5,10 +5,7 @@ from pathlib import Path
import pytest
from ultralytics.utils import ROOT
from ultralytics.utils.torch_utils import init_seeds
TMP = (ROOT / '../tests/tmp').resolve() # temp directory for test files
TMP = Path(__file__).resolve().parent / 'tmp' # temp directory for test files
def pytest_addoption(parser):
@ -62,6 +59,8 @@ def pytest_sessionstart(session):
Args:
session (pytest.Session): The pytest session object.
"""
from ultralytics.utils.torch_utils import init_seeds
init_seeds()
shutil.rmtree(TMP, ignore_errors=True) # delete any existing tests/tmp directory
TMP.mkdir(parents=True, exist_ok=True) # create a new empty directory
@ -79,10 +78,14 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
exitstatus (int): The exit status of the test run.
config (pytest.config.Config): The pytest config object.
"""
from ultralytics.utils import WEIGHTS_DIR
# Remove files
for file in ['bus.jpg', 'decelera_landscape_min.mov']:
models = [path for x in ['*.onnx', '*.torchscript'] for path in WEIGHTS_DIR.rglob(x)]
for file in ['bus.jpg', 'yolov8n.onnx', 'yolov8n.torchscript'] + models:
Path(file).unlink(missing_ok=True)
# Remove directories
for directory in [ROOT / '../.pytest_cache', TMP]:
models = [path for x in ['*.mlpackage', '*_openvino_model'] for path in WEIGHTS_DIR.rglob(x)]
for directory in [TMP.parents[1] / '.pytest_cache', TMP] + models:
shutil.rmtree(directory, ignore_errors=True)

View file

@ -1,16 +1,14 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
import subprocess
from pathlib import Path
import pytest
from ultralytics.utils import ASSETS, SETTINGS
from ultralytics.utils import ASSETS, WEIGHTS_DIR
from ultralytics.utils.checks import cuda_device_count, cuda_is_available
CUDA_IS_AVAILABLE = cuda_is_available()
CUDA_DEVICE_COUNT = cuda_device_count()
WEIGHTS_DIR = Path(SETTINGS['weights_dir'])
TASK_ARGS = [
('detect', 'yolov8n', 'coco8.yaml'),
('segment', 'yolov8n-seg', 'coco8-seg.yaml'),

View file

@ -1,19 +1,16 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
import contextlib
from pathlib import Path
import pytest
import torch
from ultralytics import YOLO, download
from ultralytics.utils import ASSETS, SETTINGS
from ultralytics.utils import ASSETS, DATASETS_DIR, WEIGHTS_DIR
from ultralytics.utils.checks import cuda_device_count, cuda_is_available
CUDA_IS_AVAILABLE = cuda_is_available()
CUDA_DEVICE_COUNT = cuda_device_count()
DATASETS_DIR = Path(SETTINGS['datasets_dir'])
WEIGHTS_DIR = Path(SETTINGS['weights_dir'])
MODEL = WEIGHTS_DIR / 'path with spaces' / 'yolov8n.pt' # test spaces in path
DATA = 'coco8.yaml'
BUS = ASSETS / 'bus.jpg'
@ -91,7 +88,7 @@ def test_predict_sam():
model(ASSETS / 'zidane.jpg', points=[900, 370], labels=[1], device=0)
# Create SAMPredictor
overrides = dict(conf=0.25, task='segment', mode='predict', imgsz=1024, model='mobile_sam.pt')
overrides = dict(conf=0.25, task='segment', mode='predict', imgsz=1024, model=WEIGHTS_DIR / 'mobile_sam.pt')
predictor = SAMPredictor(overrides=overrides)
# Set image

View file

@ -1,18 +1,16 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
from pathlib import Path
from ultralytics import YOLO
from ultralytics.cfg import get_cfg
from ultralytics.engine.exporter import Exporter
from ultralytics.models.yolo import classify, detect, segment
from ultralytics.utils import ASSETS, DEFAULT_CFG, SETTINGS
from ultralytics.utils import ASSETS, DEFAULT_CFG, WEIGHTS_DIR
CFG_DET = 'yolov8n.yaml'
CFG_SEG = 'yolov8n-seg.yaml'
CFG_CLS = 'yolov8n-cls.yaml' # or 'squeezenet1_0'
CFG = get_cfg(DEFAULT_CFG)
MODEL = Path(SETTINGS['weights_dir']) / 'yolov8n'
MODEL = WEIGHTS_DIR / 'yolov8n'
def test_func(*args): # noqa

View file

@ -14,11 +14,11 @@ from torchvision.transforms import ToTensor
from ultralytics import RTDETR, YOLO
from ultralytics.cfg import TASK2DATA
from ultralytics.data.build import load_inference_source
from ultralytics.utils import ASSETS, DEFAULT_CFG, LINUX, MACOS, ONLINE, ROOT, SETTINGS, WINDOWS, is_dir_writeable
from ultralytics.utils import (ASSETS, DEFAULT_CFG, DEFAULT_CFG_PATH, LINUX, MACOS, ONLINE, ROOT, WEIGHTS_DIR, WINDOWS,
is_dir_writeable)
from ultralytics.utils.downloads import download
from ultralytics.utils.torch_utils import TORCH_1_9
WEIGHTS_DIR = Path(SETTINGS['weights_dir'])
MODEL = WEIGHTS_DIR / 'path with spaces' / 'yolov8n.pt' # test spaces in path
CFG = 'yolov8n.yaml'
SOURCE = ASSETS / 'bus.jpg'
@ -260,12 +260,12 @@ def test_predict_callback_and_setup():
def test_results():
for m in 'yolov8n-pose.pt', 'yolov8n-seg.pt', 'yolov8n.pt', 'yolov8n-cls.pt':
results = YOLO(m)([SOURCE, SOURCE], imgsz=160)
results = YOLO(WEIGHTS_DIR / m)([SOURCE, SOURCE], imgsz=160)
for r in results:
r = r.cpu().numpy()
r = r.to(device='cpu', dtype=torch.float32)
r.save_txt(txt_file='runs/tests/label.txt', save_conf=True)
r.save_crop(save_dir='runs/tests/crops/')
r.save_txt(txt_file=TMP / 'runs/tests/label.txt', save_conf=True)
r.save_crop(save_dir=TMP / 'runs/tests/crops/')
r.tojson(normalize=True)
r.plot(pil=True)
r.plot(conf=True, boxes=True)
@ -299,14 +299,17 @@ def test_data_converter():
file = 'instances_val2017.json'
download(f'https://github.com/ultralytics/yolov5/releases/download/v1.0/{file}', dir=TMP)
convert_coco(labels_dir=TMP, use_segments=True, use_keypoints=False, cls91to80=True)
convert_coco(labels_dir=TMP, save_dir=TMP / 'yolo_labels', use_segments=True, use_keypoints=False, cls91to80=True)
coco80_to_coco91_class()
def test_data_annotator():
from ultralytics.data.annotator import auto_annotate
auto_annotate(ASSETS, det_model='yolov8n.pt', sam_model='mobile_sam.pt', output_dir=TMP / 'auto_annotate_labels')
auto_annotate(ASSETS,
det_model=WEIGHTS_DIR / 'yolov8n.pt',
sam_model=WEIGHTS_DIR / 'mobile_sam.pt',
output_dir=TMP / 'auto_annotate_labels')
def test_events():
@ -326,6 +329,7 @@ def test_cfg_init():
with contextlib.suppress(SyntaxError):
check_dict_alignment({'a': 1}, {'b': 2})
copy_default_cfg()
(Path.cwd() / DEFAULT_CFG_PATH.name.replace('.yaml', '_copy.yaml')).unlink(missing_ok=False)
[smart_value(x) for x in ['none', 'true', 'false']]