YOLO V7项目使用

YOLO V7项目使用

根据官方论文中提供的项目地址:使用git clone将项目下载到本地。

https://github.com/WongKinYiu/yolov7

git clone https://github.com/WongKinYiu/yolov7

使用pycharm打开项目,根据官方提供的requirement.txt文件下载项目启动所需要的环境(在yolo v7的虚拟环境下)

官方的md文件中给出了需要在终端中切换的目录,和安装的命令如下所示:

cd yolov7

pip install -r requirements.txt # install

存在的问题

  1. 问题一:charset_normalizer版本不匹配问题导致循环导入模块

同样在使用yolo v7项目启动时也会和v5项目一样发生类似的报错信息。我们可以发现同样是charset_normalizer这个组件发生了问题,采用和v5相同的方法更新版本信息再一次进行尝试

Traceback (most recent call last):

AttributeError: partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)

pip 复制代码
pip install --force-reinstall charset-normalizer==3.1.0
  1. 问题二:启动时验证不通过问题

我第一次下载的项目使用的是github上下载的压缩包文件,经过解压之后导入的pycharm,在启动验证的时候缺少git相关的文件导致启动失败。(git init初始化启动也是不可以)建议还是git clone 网址或者ssh地址

  1. 问题三:项目启动时默认还是采用的cpu版本的torch和之前yolo v5产生的错误类型相同

采用同样解决方式使用conda安装GPU(CUDA)版本的torch,之后我们在执行训练模型的文件将整个YOLO v7项目启动失败(先卸载之前pip安装的cpu版本)

后面直接使用pip命令来安装GPU版本的torch命令如下

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

这是我们默认使用的就是GPU的环境。

  1. 执行训练文件时产生报错信息。(个人感觉是最大的一个问题,网上很多的资料说yolov7存在一些小的BUG建议train.py中使用绝对路径

第二个问题是数据集默认是无法下载的需要自己解压到data路径下面,我数据集就打算使用v5中使用过的coco128数据集,并参考v5的配置文件
Exception: train: Error loading data from ./coco/train2017.txt: train: coco\train2017.txt does not exist

See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data

注意训练集中不能含有cache文件否则也会进行报错_pickle.UnpicklingError: unpickling stack underflow

执行时会新建一个cache

train: New cache created: D:\Git-res\DeepLearing\DL_01\YOLOV7\yolov7\data\datasets\coco128\labels\train2017.cache

修改步骤加入自己的数据集和配置文件(配置文件格式一定参考官方的来进行

yaml 复制代码
# COCO 2017 dataset http://cocodataset.org

# download command/URL (optional)
download: bash ./scripts/get_coco.sh

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: D:\\Git-res\\DeepLearing\\DL_01\\YOLOV7\\yolov7\\data\\datasets\\coco128\\images\\train2017  # 118287 images
val: D:\\Git-res\\DeepLearing\\DL_01\\YOLOV7\\yolov7\\data\\datasets\\coco128\\images\\train2017   # 5000 images
test: D:\\Git-res\\DeepLearing\\DL_01\\YOLOV7\\yolov7\\data\\datasets\\coco128\\images\\train2017   # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794

# number of classes
nc: 80

# class names
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]

parser.add_argument('--batch-size', type=int, default=8, help='total batch size for all GPUs')

训练批次不要设置的过大否则算力不足很难跑的动

项目功能补充

  1. 使用网络摄像头进行实时的目标检测

更改配置项的参数设置default='0' (从路径改为使用本机的第一个摄像头)

复制代码
parser.add_argument('--source', type=str, default='0', help='source')
  • 注意点:提前开启摄像头权限。

在执行完成关闭程序以后会生成一个.mp4的文件

  1. YOLO v7中的拓展功能测试(关键点检测)提前手动下载所需要的yolov7-w6-pose.pt文件

  2. 执行训练过程完成整个项目的使用

相关推荐
巷95515 小时前
YOLO v2:目标检测领域的全面性进化
人工智能·yolo·目标检测
深度学习机器学习17 小时前
计算机视觉最不卷的方向:三维重建学习路线梳理
人工智能·深度学习·学习·yolo·目标检测·机器学习·计算机视觉
struggle202520 小时前
适用于 iOS 的 开源Ultralytics YOLO:应用程序和 Swift 软件包,用于在您自己的 iOS 应用程序中运行 YOLO
yolo·ios·开源·app·swift
weixin_377634842 天前
【YOLO模型】参数全面解读
yolo
武乐乐~2 天前
论文精读:YOLO-UniOW: Efficient Universal Open-World Object Detection
人工智能·yolo·目标检测
DragonnAi2 天前
【目标检测标签转换工具】YOLO 格式与 Pascal VOC XML 格式的互转详解(含完整代码)
xml·yolo·目标检测
彭祥.3 天前
大疆无人机搭载树莓派进行目标旋转检测
yolo·目标检测·目标跟踪
武乐乐~3 天前
YOLO-World:基于YOLOv8的开放词汇目标检测
人工智能·yolo·目标检测
小草cys3 天前
查看YOLO版本的三种方法
人工智能·深度学习·yolo
萧霍之3 天前
基于onnxruntime结合PyQt快速搭建视觉原型Demo
pytorch·python·yolo·计算机视觉