Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_cli.py 2.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. import subprocess
  3. from pathlib import Path
  4. import pytest
  5. from ultralytics.yolo.utils import ONLINE, ROOT, SETTINGS
  6. WEIGHT_DIR = Path(SETTINGS['weights_dir'])
  7. TASK_ARGS = [ # (task, model, data)
  8. ('detect', 'yolov8n', 'coco8.yaml'), ('segment', 'yolov8n-seg', 'coco8-seg.yaml'),
  9. ('classify', 'yolov8n-cls', 'imagenet10'), ('pose', 'yolov8n-pose', 'coco8-pose.yaml')]
  10. EXPORT_ARGS = [ # (model, format)
  11. ('yolov8n', 'torchscript'), ('yolov8n-seg', 'torchscript'), ('yolov8n-cls', 'torchscript'),
  12. ('yolov8n-pose', 'torchscript')]
  13. def run(cmd):
  14. # Run a subprocess command with check=True
  15. subprocess.run(cmd.split(), check=True)
  16. def test_special_modes():
  17. run('yolo checks')
  18. run('yolo settings')
  19. run('yolo help')
  20. @pytest.mark.parametrize('task,model,data', TASK_ARGS)
  21. def test_train(task, model, data):
  22. run(f'yolo train {task} model={model}.yaml data={data} imgsz=32 epochs=1 cache=disk')
  23. @pytest.mark.parametrize('task,model,data', TASK_ARGS)
  24. def test_val(task, model, data):
  25. run(f'yolo val {task} model={model}.pt data={data} imgsz=32')
  26. @pytest.mark.parametrize('task,model,data', TASK_ARGS)
  27. def test_predict(task, model, data):
  28. run(f"yolo predict model={model}.pt source={ROOT / 'assets'} imgsz=32 save save_crop save_txt")
  29. if ONLINE:
  30. run(f'yolo predict model={model}.pt source=https://ultralytics.com/images/bus.jpg imgsz=32')
  31. run(f'yolo predict model={model}.pt source=https://ultralytics.com/assets/decelera_landscape_min.mov imgsz=32')
  32. run(f'yolo predict model={model}.pt source=https://ultralytics.com/assets/decelera_portrait_min.mov imgsz=32')
  33. @pytest.mark.parametrize('model,format', EXPORT_ARGS)
  34. def test_export(model, format):
  35. run(f'yolo export model={model}.pt format={format}')
  36. # Slow Tests
  37. @pytest.mark.slow
  38. @pytest.mark.parametrize('task,model,data', TASK_ARGS)
  39. def test_train_gpu(task, model, data):
  40. run(f'yolo train {task} model={model}.yaml data={data} imgsz=32 epochs=1 device="0"') # single GPU
  41. run(f'yolo train {task} model={model}.pt data={data} imgsz=32 epochs=1 device="0,1"') # Multi GPU
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...