- 更新 README.md 中的 ONNX构建指南,增加新版本的安装步骤 - 在 runs/detect/final_model 和 runs/detect/train 目录下添加训练配置文件 args.yaml - 配置文件包含模型训练的各种参数设置,为后续训练提供详细配置
30 lines
771 B
Python
30 lines
771 B
Python
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必须的入口保护
|