license: gpl
pipeline_tag: object-detection
tags:
- ultralytics
- yolo
- yolov10
- object-detection
石头剪刀布目标检测模型
FRC 578团队开发
模型说明
本YOLO v10小模型仅用于教学演示,旨在向学生展示目标检测模型的运作原理。模型训练周期为10个epoch。
训练数据
使用从网络获取的100张图像进行训练,未进行任何图像增强处理。
性能指标
类别 |
图像数 |
实例数 |
框准确率 |
召回率 |
mAP50 |
mAP50-95 |
全部 |
100 |
260 |
0.917 |
0.795 |
0.925 |
0.735 |
石头 |
69 |
84 |
0.875 |
0.835 |
0.924 |
0.728 |
布 |
56 |
65 |
0.899 |
0.815 |
0.909 |
0.721 |
剪刀 |
88 |
111 |
0.976 |
0.736 |
0.943 |
0.755 |
使用方法
pip install ultralytics
pip install huggingface_hub
from ultralytics import YOLO
from huggingface_hub import hf_hub_download
from matplotlib import pyplot as plt
# 从仓库加载权重
model_path = hf_hub_download(
local_dir=".",
repo_id="fairportrobotics/rock-paper-scissors",
filename="model.pt"
)
model = YOLO(model_path)
# 加载测试图像
sample_path = hf_hub_download(
local_dir=".",
repo_id="fairportrobotics/rock-paper-scissors",
filename="sample.jpg"
)
# 执行预测
res = model.predict(
source=sample_path,
project='.',
name='detected',
exist_ok=True,
save=True,
show=False,
show_labels=True,
show_conf=True,
conf=0.5
)
plt.figure(figsize=(15,10))
plt.imshow(plt.imread('detected/sample.jpg'))
plt.show()
如您所见,这个模型并不完美 ;)
使用摄像头实时检测
from ultralytics import YOLO
import cv2
import math
from huggingface_hub import hf_hub_download
# 启动摄像头
cap = cv2.VideoCapture(0)
cap.set(3, 640)
cap.set(4, 480)
# 从仓库加载权重
model_path = hf_hub_download(
local_dir=".",
repo_id="fairportrobotics/rock-paper-scissors",
filename="model.pt"
)
model = YOLO(model_path)
# 类别名称
classNames = ["石头", "布", "剪刀"]
while True:
success, img = cap.read()
results = model(img, stream=True)
# 坐标处理
for r in results:
boxes = r.boxes
for box in boxes:
# 边界框坐标
x1, y1, x2, y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
# 绘制检测框
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 3)
# 置信度
confidence = math.ceil((box.conf[0]*100))/100
# 类别索引
cls = int(box.cls[0])
# 标注信息
org = [x1, y1]
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
color = (255, 0, 0)
thickness = 2
cv2.putText(img, classNames[cls] + " " + str(round(confidence,2)), org, font, fontScale, color, thickness)
cv2.imshow('摄像头画面', img)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()