

说明
实现在yolov5训练出模型,然后在rv1126设备上运行。
操作过程简述
在YOLOV5中训练出 xxx.pt 模型
将pt转为onnx模型
将onnx转为rknn模型
部署rknn模型
环境特别说明
YOLOV5的运行环境是python3.8的,而rv1126的开发环境toolkit目前只支持到python 3.6的(linux),因此,需要两个python的环境
环境的管理采用conda
YOLOV5 环境 (python 3.8)
- 下载YOLOV5的代码: https://github.com/airockchip/yolov5 f022f01b2070dfd415c4eb8f33da2677afe8bfa2
修改 requirements.txt, 要打开 onnx coremltools
# export -------------------------------------- coremltools==4.0 onnx>=1.8.0 # scikit-learn==0.19.2 # for coreml quantization
安装requirements.txt (采用清华源,比较快)
pip3 install -r requirements.txt -i <https://pypi.tuna.tsinghua.edu.cn/simple>
训练出 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
- 转换为 onnx 文件
python3.8 models/export.py --weights yolov5s.pt --img 640 --batch 1
接下来就转到 rknn-toolkit的环境
rknn-toolkit 环境 (python 3.6)
环境安装
<https://github.com/rockchip-linux/rknn-toolkit>
onnx 转为 rknn
可参考 toolkit/example/onnx/yolov5/test.py 写一个转成rknn的即可在RV1126 的部署(python版)
toolkit 是支持python 或者C API的, 这里部署 python 版的.
注意:由于 rv1126 版本是仅支持 RKNNLite ,因此需要将toolkit 的 example 改为 RKNNLite
问题
_pickle.UnpicklingError: STACK_GLOBAL requires str
在使用YOLOv5进行训练时,可能会出现_pickle.UnpicklingError: STACK_GLOBAL requires str 这样的错误,解决办法是,将数据集中的labels.cache文件删掉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)
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)
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
-
浏览量:1022次2022-10-31 15:07:27
-
浏览量:667次2022-11-22 09:58:36
-
浏览量:548次2022-11-22 09:26:53
-
浏览量:657次2022-11-22 10:37:11
-
浏览量:1765次2021-06-18 16:05:42
-
浏览量:3517次2022-05-11 15:14:51
-
浏览量:990次2022-10-09 10:38:23
-
浏览量:5093次2021-04-01 17:04:01
-
浏览量:4372次2021-04-01 16:24:41
-
浏览量:4395次2021-04-01 16:47:04
-
浏览量:2425次2021-04-01 13:54:47
-
浏览量:3059次2021-04-02 09:47:41
-
浏览量:3535次2021-03-30 17:33:20
-
浏览量:127次2023-01-31 22:36:19
-
浏览量:2882次2022-06-11 13:46:26
-
浏览量:5027次2021-04-01 16:50:31
-
浏览量:1414次2021-06-12 17:32:52
-
浏览量:7071次2020-11-17 15:41:28
-
浏览量:490次2023-01-11 16:49:09


杨康





