🚀 石頭剪刀布目標檢測模型
本模型由FRC團隊578創建,是一個基於YOLO v10的小型目標檢測模型,專門為教學目的而訓練,旨在向學生展示目標檢測模型的工作原理。
🚀 快速開始
安裝依賴
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 = ["rock", "paper", "scissors"]
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('Webcam', img)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
✨ 主要特性
- 教育用途:專為教學設計,幫助學生理解目標檢測模型的工作原理。
- YOLO v10架構:基於先進的YOLO v10小型模型。
📦 安裝指南
使用pip
安裝所需的庫:
pip install ultralytics
pip install huggingface_hub
📚 詳細文檔
訓練數據
該模型在網上收集的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 |
📄 許可證
本項目採用GPL許可證。