diff --git a/test.py b/test.py index f550a13..a6ee093 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,29 @@ from ultralytics import YOLO +import os -model = YOLO("yolov12s.yaml") -print("Model loaded successfully!") + +def main(): + # 加载训练后的模型 + model = YOLO("runs/detect/final_model3/weights/best.pt") + + # 在验证集上评估模型性能(添加 workers=0 参数) + results2 = model.val(data="data.yaml", workers=0) + + # 推理指定图像或目录(添加 workers=0 参数) + results = model.predict( + source="datasets/test/images/3383011008094_mp4-19_jpg.rf.377dffeb92226013b2abf60eb66473a7.jpg", + imgsz=640, + conf=0.25, + save=True, + #device=0, + workers=0 # 关键参数 + ) + + # 遍历并打印预测结果 + for result in results: + print(result.names) + print(result.boxes) + + +if __name__ == '__main__': + main() # Windows必须的入口保护