如何使用深度学习目标检测算法Yolov5训练手势手语识别数据集 建立基于YOLOv5的手势手语识别:从数据准备到模型训练及性能评估的全流程指南

基于 YOLOv5 的手势手语识别数据集


以下文字及代码仅供参考。

手势手语识别数据集
在这里插入图片描述
YOLOv5目标检测 nc: 106 names: [‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’, ‘additional’, ‘alcohol’, ‘allergy’, ‘bacon’, ‘bag’, ‘barbecue’, ‘bill’, ‘biscuit’, ‘bitter’, ‘bread’, ‘burger’, ‘bye’, ‘cake’, ‘cash’, ‘cheese’, ‘chicken’, ‘coke’, ‘cold’, ‘cost’, ‘coupon’, ‘credit card’, ‘cup’, ‘dessert’, ‘drink’, ‘drive’, ‘eat’, ‘eggs’, ‘enjoy’, ‘fork’, ‘french fries’, ‘fresh’, ‘hello’, ‘hot’, ‘icecream’, ‘ingredients’, ‘juicy’, ‘ketchup’, ‘lactose’, ‘lettuce’, ‘lid’, ‘manager’, ‘menu’, ‘milk’, ‘mustard’, ‘napkin’, ‘no’, ‘order’, ‘pepper’, ‘pickle’, ‘pizza’, ‘please’, ‘ready’, ‘receipt’, ‘refill’, ‘repeat’, ‘safe’, ‘salt’, ‘sandwich’, ‘sauce’, ‘small’, ‘soda’, ‘sorry’, ‘spicy’, ‘spoon’, ‘straw’, ‘sugar’, ‘sweet’, ‘thank-you’, ‘tissues’, ‘tomato’, ‘total’, ‘urgent’, ‘vegetables’, ‘wait’, ‘warm’, ‘water’, ‘what’, ‘would’, ‘yoghurt’, ‘your’]
在这里插入图片描述

1
在这里插入图片描述
基于 YOLOv5 的手势手语识别数据集的完整处理流程,包括数据准备、格式转换、数据划分、环境搭建、模型训练、推理和性能评估。我使用提供的 nc: 106 和类别名称进行配置。


1. 数据准备

1.1 数据目录结构

假设数据集目录结构如下:

dataset/
├── images/
│   ├── train/
│   │   ├── img1.jpg
│   │   ├── img2.jpg
│   │   └── ...
│   ├── val/
│   │   ├── img1.jpg
│   │   ├── img2.jpg
│   │   └── ...
├── labels/
│   ├── train/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
│   ├── val/
│   │   ├── img1.txt
│   │   ├── img2.txt
│   │   └── ...
  • 图像文件存储在 images/train/images/val/
  • 标注文件(YOLO格式)存储在 labels/train/labels/val/
1.2 YOLO 格式标注

每张图像对应的 .txt 文件包含以下内容:

<object-class> <x_center> <y_center> <width> <height>
  • <object-class>:类别索引(从 0 开始)。
  • <x_center>, <y_center>, <width>, <height>:归一化到 [0, 1] 的边界框坐标。

2. 环境搭建

安装依赖并克隆 YOLOv5 仓库:

# 安装 Python 环境
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117  # CUDA 版本
pip install -r requirements.txt

# 克隆 YOLOv5 仓库
git clone https://github.com/ultralytics/yolov5
cd yolov5

3. 数据配置

3.1 创建数据配置文件

创建 data.yaml 文件,定义数据集路径和类别信息:

train: ../dataset/images/train
val: ../dataset/images/val

nc: 106
names: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'additional', 'alcohol', 'allergy', 'bacon', 'bag', 'barbecue', 'bill', 'biscuit', 'bitter', 'bread', 'burger', 'bye', 'cake', 'cash', 'cheese', 'chicken', 'coke', 'cold', 'cost', 'coupon', 'credit card', 'cup', 'dessert', 'drink', 'drive', 'eat', 'eggs', 'enjoy', 'fork', 'french fries', 'fresh', 'hello', 'hot', 'icecream', 'ingredients', 'juicy', 'ketchup', 'lactose', 'lettuce', 'lid', 'manager', 'menu', 'milk', 'mustard', 'napkin', 'no', 'order', 'pepper', 'pickle', 'pizza', 'please', 'ready', 'receipt', 'refill', 'repeat', 'safe', 'salt', 'sandwich', 'sauce', 'small', 'soda', 'sorry', 'spicy', 'spoon', 'straw', 'sugar', 'sweet', 'thank-you', 'tissues', 'tomato', 'total', 'urgent', 'vegetables', 'wait', 'warm', 'water', 'what', 'would', 'yoghurt', 'your']

4. 模型训练

4.1 配置超参数

创建或修改 hyp.scratch.yaml 文件,调整超参数(如学习率、权重衰减等)。

4.2 启动训练

运行以下命令启动训练:

python train.py --img 640 --batch 16 --epochs 50 --data data.yaml --cfg yolov5s.yaml --weights yolov5s.pt --name hand_gesture_detection
  • --img 640:输入图像大小为 640x640。
  • --batch 16:批量大小为 16。
  • --epochs 50:训练 50 个 epoch。
  • --cfg yolov5s.yaml:使用 YOLOv5 小型模型。
  • --weights yolov5s.pt:预训练权重。
  • --name hand_gesture_detection:保存实验结果的名称。

5. 模型推理

5.1 单张图像推理

使用训练好的模型对单张图像进行推理:

python detect.py --weights runs/train/hand_gesture_detection/weights/best.pt --img 640 --conf 0.25 --source path/to/image.jpg
5.2 批量推理

对整个文件夹的图像进行推理:

python detect.py --weights runs/train/hand_gesture_detection/weights/best.pt --img 640 --conf 0.25 --source path/to/test_images/

6. 性能评估

6.1 计算 mAP

运行以下命令评估模型性能:

python val.py --data data.yaml --weights runs/train/hand_gesture_detection/weights/best.pt --img 640 --task test

输出包括 mAP(平均精度均值)、Precision(精确率)、Recall(召回率)等指标。


7. 推理代码(Python API)

如果需要将 YOLOv5 集成到自定义代码中,可以使用以下代码:

from PIL import Image
import torch
from yolov5 import detect

# 加载模型
model = torch.hub.load('ultralytics/yolov5', 'custom', path='runs/train/hand_gesture_detection/weights/best.pt')

# 推理单张图像
img_path = 'path/to/image.jpg'
results = model(img_path)

# 显示结果
results.show()  # 可视化
print(results.pandas().xyxy[0])  # 打印检测结果

仅供参考,我的同学们。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值