ComView/test.py

30 lines
771 B
Python
Raw Permalink Normal View History

from ultralytics import YOLO
import os
def main():
# 加载训练后的模型
model = YOLO("runs/detect/final_model/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必须的入口保护