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.
74 lines
1.5 KiB
74 lines
1.5 KiB
2 years ago
|
import torch
|
||
|
|
||
2 years ago
|
from ultralytics.yolo import YOLO
|
||
|
|
||
|
|
||
2 years ago
|
def test_model_forward():
|
||
|
model = YOLO()
|
||
2 years ago
|
model.new("yolov8n-seg.yaml")
|
||
2 years ago
|
img = torch.rand(512 * 512 * 3).view(1, 3, 512, 512)
|
||
|
model.forward(img)
|
||
|
model(img)
|
||
|
|
||
|
|
||
|
def test_model_info():
|
||
|
model = YOLO()
|
||
2 years ago
|
model.new("yolov8n.yaml")
|
||
2 years ago
|
model.info()
|
||
|
model.load("balloon-detect.pt")
|
||
|
model.info(verbose=True)
|
||
|
|
||
|
|
||
|
def test_model_fuse():
|
||
|
model = YOLO()
|
||
2 years ago
|
model.new("yolov8n.yaml")
|
||
2 years ago
|
model.fuse()
|
||
|
model.load("balloon-detect.pt")
|
||
|
model.fuse()
|
||
|
|
||
|
|
||
|
def test_visualize_preds():
|
||
2 years ago
|
model = YOLO()
|
||
2 years ago
|
model.load("balloon-segment.pt")
|
||
|
model.predict(source="ultralytics/assets")
|
||
|
|
||
|
|
||
|
def test_val():
|
||
|
model = YOLO()
|
||
|
model.load("balloon-segment.pt")
|
||
2 years ago
|
model.val(data="coco128-seg.yaml", imgsz=32)
|
||
2 years ago
|
|
||
|
|
||
|
def test_model_resume():
|
||
|
model = YOLO()
|
||
2 years ago
|
model.new("yolov8n-seg.yaml")
|
||
2 years ago
|
model.train(epochs=1, imgsz=32, data="coco128-seg.yaml")
|
||
2 years ago
|
try:
|
||
|
model.resume(task="segment")
|
||
|
except AssertionError:
|
||
|
print("Successfully caught resume assert!")
|
||
|
|
||
|
|
||
2 years ago
|
def test_model_train_pretrained():
|
||
|
model = YOLO()
|
||
|
model.load("balloon-detect.pt")
|
||
2 years ago
|
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
||
2 years ago
|
model.new("yolov8n.yaml")
|
||
2 years ago
|
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
||
2 years ago
|
img = torch.rand(512 * 512 * 3).view(1, 3, 512, 512)
|
||
|
model(img)
|
||
|
|
||
|
|
||
2 years ago
|
def test():
|
||
|
test_model_forward()
|
||
|
test_model_info()
|
||
|
test_model_fuse()
|
||
|
test_visualize_preds()
|
||
|
test_val()
|
||
|
test_model_resume()
|
||
2 years ago
|
test_model_train_pretrained()
|
||
2 years ago
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
2 years ago
|
test()
|