yolo训练部署相关代码

This commit is contained in:
BBIT-Kai
2025-11-10 18:08:01 +08:00
parent c098cec233
commit 9527cc2f1c
4 changed files with 286 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
from ultralytics import YOLO
import os
# 设置工作目录
os.chdir("/home/bbit/mine/yolo/")
# 加载模型
model = YOLO("runs/detect/train13/weights/best.pt")
# 输入图片路径
img_path = "valid/raw_1.jpg"
# 推理
results = model(img_path)
# 生成输出路径(同目录下)
save_path = os.path.splitext(img_path)[0] + "_detected.jpg"
# 保存检测结果
results[0].save(filename=save_path)
print(f"检测结果已保存至: {save_path}")