ultralytics 8.0.163 add new gpu-latest runner to CI actions (#4565)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maia Numerosky <17316848+maianumerosky@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2023-08-26 03:45:19 +02:00 committed by GitHub
parent 431cef3955
commit b4dca690d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 153 additions and 17 deletions

View file

@ -44,5 +44,5 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
Path(file).unlink(missing_ok=True)
# Remove directories
for directory in ['.pytest_cache/', TMP]:
for directory in [ROOT / '../.pytest_cache', TMP]:
shutil.rmtree(directory, ignore_errors=True)

View file

@ -63,7 +63,7 @@ def test_export(model, format):
def test_rtdetr(task='detect', model='yolov8n-rtdetr.yaml', data='coco8.yaml'):
# Warning: MUST use imgsz=640
run(f'yolo train {task} model={model} data={data} imgsz=640 epochs=1, cache = disk') # add coma, space to args
run(f'yolo train {task} model={model} data={data} --imgsz= 640 epochs =1, cache = disk') # add coma, spaces to args
run(f"yolo predict {task} model={model} source={ASSETS / 'bus.jpg'} imgsz=640 save save_crop save_txt")

73
tests/test_cuda.py Normal file
View file

@ -0,0 +1,73 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
import subprocess
from pathlib import Path
import pytest
import torch
from ultralytics import YOLO
from ultralytics.utils import ASSETS, SETTINGS
CUDA_IS_AVAILABLE = torch.cuda.is_available()
CUDA_DEVICE_COUNT = torch.cuda.device_count()
WEIGHTS_DIR = Path(SETTINGS['weights_dir'])
MODEL = WEIGHTS_DIR / 'path with spaces' / 'yolov8n.pt' # test spaces in path
DATA = 'coco8.yaml'
def test_checks():
from ultralytics.utils.checks import cuda_device_count, cuda_is_available
assert cuda_device_count() == CUDA_DEVICE_COUNT
assert cuda_is_available() == CUDA_IS_AVAILABLE
@pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason='CUDA is not available')
def test_train():
YOLO(MODEL).train(data=DATA, imgsz=64, epochs=1, batch=-1, device=0) # also test AutoBatch, requires imgsz>=64
@pytest.mark.skipif(CUDA_DEVICE_COUNT < 2, reason=f'DDP is not available, {CUDA_DEVICE_COUNT} device(s) found')
def test_train_ddp():
YOLO(MODEL).train(data=DATA, imgsz=64, epochs=1, device=[0, 1]) # requires imgsz>=64
@pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason='CUDA is not available')
def test_utils_benchmarks():
from ultralytics.utils.benchmarks import ProfileModels
YOLO(MODEL).export(format='engine', imgsz=32, dynamic=True, batch=1) # pre-export engine model, auto-device
ProfileModels([MODEL], imgsz=32, half=False, min_time=1, num_timed_runs=3, num_warmup_runs=1).profile()
@pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason='CUDA is not available')
def test_predict_sam():
from ultralytics import SAM
# Load a model
model = SAM(WEIGHTS_DIR / 'sam_b.pt')
# Display model information (optional)
model.info()
# Run inference
model(ASSETS / 'bus.jpg', device=0)
# Run inference with bboxes prompt
model(ASSETS / 'zidane.jpg', bboxes=[439, 437, 524, 709], device=0)
# Run inference with points prompt
model(ASSETS / 'zidane.jpg', points=[900, 370], labels=[1], device=0)
@pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason='CUDA is not available')
def test_model_tune():
subprocess.run('pip install ray[tune]'.split(), check=True)
YOLO('yolov8n-cls.yaml').tune(data='imagenet10',
grace_period=1,
max_samples=1,
imgsz=32,
epochs=1,
plots=False,
device='cpu')

View file

@ -1,5 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
import contextlib
import shutil
from copy import copy
from pathlib import Path
@ -38,6 +39,8 @@ def test_model_methods():
model = model.load(MODEL)
model.to('cpu')
model.fuse()
model.clear_callback('on_train_start')
model._reset_callbacks()
# Model properties
_ = model.names
@ -314,6 +317,15 @@ def test_events():
events(cfg)
def test_cfg_init():
from ultralytics.cfg import check_dict_alignment, copy_default_cfg, smart_value
with contextlib.suppress(SyntaxError):
check_dict_alignment({'a': 1}, {'b': 2})
copy_default_cfg()
[smart_value(x) for x in ['none', 'true', 'false']]
def test_utils_init():
from ultralytics.utils import get_git_branch, get_git_origin_url, get_ubuntu_version, is_github_actions_ci
@ -354,6 +366,7 @@ def test_utils_torchutils():
time_sync()
@pytest.mark.skipif(not ONLINE, reason='environment is offline')
def test_utils_downloads():
from ultralytics.utils.downloads import get_google_drive_file_info
@ -422,8 +435,11 @@ def test_nn_modules_block():
BottleneckCSP(c1, c2)(x)
@pytest.mark.skipif(not ONLINE, reason='environment is offline')
def test_hub():
from ultralytics.hub import export_fmts_hub, logout
from ultralytics.hub.utils import smart_request
export_fmts_hub()
logout()
smart_request('GET', 'http://github.com', progress=True)