You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
2.7 KiB
111 lines
2.7 KiB
2 years ago
|
from pathlib import Path
|
||
|
|
||
2 years ago
|
import torch
|
||
|
|
||
2 years ago
|
from ultralytics import YOLO
|
||
2 years ago
|
from ultralytics.yolo.utils import ROOT, SETTINGS
|
||
2 years ago
|
|
||
2 years ago
|
MODEL = Path(SETTINGS['weights_dir']) / 'yolov8n.pt'
|
||
2 years ago
|
CFG = 'yolov8n.yaml'
|
||
|
|
||
2 years ago
|
|
||
2 years ago
|
def test_model_forward():
|
||
2 years ago
|
model = YOLO(CFG)
|
||
2 years ago
|
img = torch.rand(1, 3, 320, 320)
|
||
2 years ago
|
model.forward(img)
|
||
|
model(img)
|
||
|
|
||
|
|
||
|
def test_model_info():
|
||
2 years ago
|
model = YOLO(CFG)
|
||
2 years ago
|
model.info()
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.info(verbose=True)
|
||
|
|
||
|
|
||
|
def test_model_fuse():
|
||
2 years ago
|
model = YOLO(CFG)
|
||
2 years ago
|
model.fuse()
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.fuse()
|
||
|
|
||
|
|
||
2 years ago
|
def test_predict_dir():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.predict(source=ROOT / "assets")
|
||
2 years ago
|
|
||
|
|
||
|
def test_val():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.val(data="coco128.yaml", imgsz=32)
|
||
2 years ago
|
|
||
|
|
||
2 years ago
|
def test_train_scratch():
|
||
2 years ago
|
model = YOLO(CFG)
|
||
2 years ago
|
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
||
2 years ago
|
img = torch.rand(1, 3, 320, 320)
|
||
2 years ago
|
model(img)
|
||
|
|
||
|
|
||
2 years ago
|
def test_train_pretrained():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
||
|
img = torch.rand(1, 3, 320, 320)
|
||
|
model(img)
|
||
|
|
||
|
|
||
|
def test_export_torchscript():
|
||
2 years ago
|
"""
|
||
|
Format Argument Suffix CPU GPU
|
||
|
0 PyTorch - .pt True True
|
||
|
1 TorchScript torchscript .torchscript True True
|
||
|
2 ONNX onnx .onnx True True
|
||
|
3 OpenVINO openvino _openvino_model True False
|
||
|
4 TensorRT engine .engine False True
|
||
|
5 CoreML coreml .mlmodel True False
|
||
|
6 TensorFlow SavedModel saved_model _saved_model True True
|
||
|
7 TensorFlow GraphDef pb .pb True True
|
||
|
8 TensorFlow Lite tflite .tflite True False
|
||
|
9 TensorFlow Edge TPU edgetpu _edgetpu.tflite False False
|
||
|
10 TensorFlow.js tfjs _web_model False False
|
||
|
11 PaddlePaddle paddle _paddle_model True True
|
||
|
"""
|
||
|
from ultralytics.yolo.engine.exporter import export_formats
|
||
|
print(export_formats())
|
||
|
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.export(format='torchscript')
|
||
2 years ago
|
|
||
|
|
||
|
def test_export_onnx():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.export(format='onnx')
|
||
2 years ago
|
|
||
|
|
||
|
def test_export_openvino():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.export(format='openvino')
|
||
2 years ago
|
|
||
|
|
||
|
def test_export_coreml():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.export(format='coreml')
|
||
|
|
||
|
|
||
2 years ago
|
def test_export_paddle():
|
||
2 years ago
|
model = YOLO(MODEL)
|
||
2 years ago
|
model.export(format='paddle')
|
||
2 years ago
|
|
||
|
|
||
2 years ago
|
def test_all_model_yamls():
|
||
|
for m in list((ROOT / 'yolo/v8/models').rglob('*.yaml')):
|
||
|
YOLO(m.name)
|
||
|
|
||
|
|
||
2 years ago
|
# def run_all_tests(): # do not name function test_...
|
||
|
# pass
|
||
|
#
|
||
|
#
|
||
|
# if __name__ == "__main__":
|
||
|
# run_all_tests()
|