YOLOV5移植RV1126说明

YOLOV5移植RV1126说明

说明

实现在yolov5训练出模型,然后在rv1126设备上运行。

操作过程简述

  1. 在YOLOV5中训练出 xxx.pt 模型
  2. 将pt转为onnx模型
  3. 将onnx转为rknn模型
  4. 部署rknn模型

环境特别说明

YOLOV5的运行环境是python3.8的,而rv1126的开发环境toolkit目前只支持到python 3.6的(linux),因此,需要两个python的环境
环境的管理采用conda

YOLOV5 环境 (python 3.8)

  1. 下载YOLOV5的代码: https://github.com/airockchip/yolov5 f022f01b2070dfd415c4eb8f33da2677afe8bfa2
  2. 修改 requirements.txt, 要打开 onnx coremltools
# export --------------------------------------
coremltools==4.0
onnx>=1.8.0
# scikit-learn==0.19.2  # for coreml quantization
  1. 安装requirements.txt (采用清华源,比较快)
pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 训练出 pt 文件
# 以训练 coco128 为例
python3.8 train.py --img 640 --batch 16 --epochs 5 --device cpu --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml

注:这里训练默认会以 yolov5s.pt 作模版训练的,如果是全新训练的话,需要改一下 --weights ‘’, 训练完成后,可先执行如下操作验证一下

python3 detect.py --source $1 --weight yolov5s.pt --conf-thres 0.3 --device cpu
  1. 转换为 onnx 文件
python3.8 models/export.py --weights yolov5s.pt --img 640 --batch 1

接下来就转到 rknn-toolkit的环境

rknn-toolkit 环境 (python 3.6)

  1. 环境安装
https://github.com/rockchip-linux/rknn-toolkit
  1. onnx 转为 rknn
    可参考 toolkit/example/onnx/yolov5/test.py 写一个转成rknn的即可

  2. 在RV1126 的部署(python版)
    toolkit 是支持python 或者C API的, 这里部署 python 版的.
    注意:由于 rv1126 版本是仅支持 RKNNLite ,因此需要将toolkit 的 example 改为 RKNNLite

问题

1. _pickle.UnpicklingError: STACK_GLOBAL requires str

在使用YOLOv5进行训练时,可能会出现_pickle.UnpicklingError: STACK_GLOBAL requires str 这样的错误,解决办法是,将数据集中的labels.cache文件删掉

2. RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place

https://blog.csdn.net/weixin_44612221/article/details/115359866
找到在File "models\yolo.py"的line 145
将代码修改为:

    def _initialize_biases(self, cf=None):  # initialize biases into Detect(), cf is class frequency
        # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
        m = self.model[-1]  # Detect() module
        for mi, s in zip(m.m, m.stride):  # from
            b = mi.bias.view(m.na, -1)  # conv.bias(255) to (3,85)
            with torch.no_grad():
                b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
                b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum())  # cls
            mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)

3. AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor

https://blog.csdn.net/weixin_43401024/article/details/124428432
1.点击报错行该路径,进入编辑页, upsampling.py 修改forward函数

    return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值