• 【CV项目实现】edgeaiyolov5的实现过程


    前言

    博主之前使用yolov5进行训练和测试,但是在部署的时候,根据部署平台的不同,实现过程也有所不同。一般对于nvidia的显卡,可以使用pytorch转onnx转tensorrt进行部署,需要熟悉tensorrt的实现过程,甚至cuda编程。也可以根据部署平台的固网文档进行部署,比如高通的SNPE,TI的TDA4。

    直接使用yolov5的训练模型在TDA4上进行转换,会出现较多错误,主要原因是TDA4平台的算子操作的支持度。比较好的是,TDA4给出了yolov5根据TDA4平台的改进版本,可以直接训练和转换,并在TDA4平台上移植部署。

    一、安装edgeai-yolov5的环境 

    博主在3080TI上安装,需要comment文件requirements.txt中torch版本相关的内容,因为3080Ti只能适用CUDA以上的版本;
    conda remove -n edgeai --all  # 删除不需要的conda环境
    conda create -n edgeai python=3.8 -y
    conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch  # 最新版本的pytorch,也可以指定pytorch版本
    pip install -r requirements.txt
     问题:
    NVIDIA GeForce RTX 3080 Ti with CUDA capability sm_86 is not compatible with the current PyTorch installation.
    The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70.
    RuntimeError: CUDA error: no kernel image is available for execution on the device
    CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
    For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

    原因:

    根据对应算力的话,算力为8.x的显卡使用的cuda版本应该大于等于11.0。
    因为3080Ti只能适用CUDA11.0以上的版本;需要重新安装对应CUDA可用版本的pytorch版本;
     
    二、训练
    cmd
    # coco
    python train.py --data coco.yaml --cfg yolov5s6.yaml --weights '' --batch-size 32
    # LISA
    python train.py --data data/Lisa2coco128.yaml --cfg yolov5s6.yaml --weights '' --batch-size 64
    直接重新训练Lisa数据集,每个epoch平均需要200s,300个epochs共需要16-17个小时;
    问题
    Unable to find a valid cuDNN algorithm to run convolution

    解决方法:

    当测试yolov5x.pt这个模型进行预训练的时候,会报Unable to find a valid cuDNN algorithm to run convolution这个错误,当你重新安装cudnn后仍然不能解决问题。其实这个问题很简单,并不是我们的cudnn出问题了。而是,由于yolov5x属于大模型。显存可能不足,这时候只需调小batch_size即可。
     
    三、模型转换
    python export.py --weights runs/train/exp6/weights/best.pt  --img 640 --batch 1 --simplify --export-nms --opset 11
    # export onnx必须添加--dynamic
    python export.py --weights runs/train/exp6/weights/best.pt  --img 640 --batch 1 --simplify --export-nms --opset 11 --dynamic
    # valid
    python val.py --data data/Lisa2coco128.yaml --img 640 --conf 0.001 --iou 0.45 --weights runs/train/exp6/weights/best.pt
    # detect pt
    python detect.py --source ../tensorRT_Pro/workspace/inference --weights runs/train/exp6/weights/best.pt --img 640
    # 测试onnx
    python detect.py --source ../tensorRT_Pro/workspace/inference --weights runs/train/exp6/weights/best.onnx --img 640

    问题

    TypeError: 'float' object is not subscriptable 

    解决方法here

    # 将错误处
    coords[:, [0, 2]] /= gain[1]
    coords[:, [1, 3]] /= gain[0]
    # 替换为
    coords[:, [0, 2]] /= gain
    coords[:, [1, 3]] /= gain
     转ti模型以及移植测试需要安装交叉编译环境;转onnx之后,测试效果会有所下降,和转换成ti模型之后,在交叉编译环境中测试效果将又有下降。

    参考

    1. edgeai_yolov5_github

    2. yolov5_github;

    3. 【问题解决】YOLOv5遇到Unable to find a valid cuDNN algorithm to run convolution

  • 相关阅读:
    496. 下一个更大元素 I 力扣(简单) 单调栈
    240. 搜索二维矩阵 II 力扣(中等) Z字型查找
    638. 大礼包 力扣(中等) 记忆化搜索,弱点
    453. 最小操作次数使数组元素相等 力扣(简单) 没想出来
    传纸条
    同余方程
    花匠
    华容道
    货车运输
    火柴排队
  • 原文地址:https://www.cnblogs.com/happyamyhope/p/16424277.html
Copyright © 2020-2023  润新知