ultralytics 8.0.188 fix .grad attribute leaf Tensor Warning (#5094)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2023-09-26 20:28:45 +02:00 committed by GitHub
parent f2ed207571
commit 19c3314e68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 78 additions and 41 deletions

View file

@ -16,6 +16,7 @@ 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'
def test_checks():
@ -29,6 +30,30 @@ def test_train():
YOLO(MODEL).train(data=DATA, imgsz=64, epochs=1, device=device) # requires imgsz>=64
@pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason='CUDA is not available')
def test_predict_multiple_devices():
model = YOLO('yolov8n.pt')
model = model.cpu()
assert str(model.device) == 'cpu'
_ = model(BUS) # CPU inference
assert str(model.device) == 'cpu'
model = model.to('cuda:0')
assert str(model.device) == 'cuda:0'
_ = model(BUS) # CUDA inference
assert str(model.device) == 'cuda:0'
model = model.cpu()
assert str(model.device) == 'cpu'
_ = model(BUS) # CPU inference
assert str(model.device) == 'cpu'
model = model.cuda()
assert str(model.device) == 'cuda:0'
_ = model(BUS) # CUDA inference
assert str(model.device) == 'cuda:0'
@pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason='CUDA is not available')
def test_autobatch():
from ultralytics.utils.autobatch import check_train_batch_size
@ -57,10 +82,10 @@ def test_predict_sam():
model.info()
# Run inference
model(ASSETS / 'bus.jpg', device=0)
model(BUS, device=0)
# Run inference with bboxes prompt
model(ASSETS / 'zidane.jpg', bboxes=[439, 437, 524, 709], device=0)
model(BUS, bboxes=[439, 437, 524, 709], device=0)
# Run inference with points prompt
model(ASSETS / 'zidane.jpg', points=[900, 370], labels=[1], device=0)