当前位置: 首页 > article >正文

ELF2开发板(飞凌嵌入式)部署yolov5s的自定义模型

ELF2开发板(飞凌嵌入式)部署yolov5s的自定义模型

本人将零基础教学自己训练的yolov5s模型部署于飞凌的elf2开发板,利用RKNN-Toolkit2对模型进行转化为rknn模型,在开发板上进行推理。

获得自定义训练得到的yolov5s pt模型

准备自定义数据集(博主用的是VOC数据集)

  • 数据集目录结构如下:
└─VOC2028:		自定义数据集
    ├─Annotations	存放的是数据集标签文件,xml格式
    ├─ImageSets		数据集的划分文件
    │  └─Main
    ├─JPEGImages	存放的是数据集图片
  • 分割数据集

在split_train_val.py文件路径下执行python3 split_train_val.py会得到一下目录结构:

└─VOC2028:		自定义数据集
    ├─Annotations	存放的是数据集标签文件,xml格式
    ├─ImageSets		数据集的划分文件
    │  └─Main test.txt
          └─test.txt
          └─train.txt
          └─val.txt
    ├─JPEGImages	存放的是数据集图片
    ├─split_train_val.py	分割数据集的py文件

split_train_val.py文件代码如下

# -*- coding: utf-8 -*-
"""
Author:dragonforward
简介:分训练集、验证集和测试集,按照 8:1:1 的比例来分,训练集8,验证集1,测试集1
"""
import os
import random
import argparse

parser = argparse.ArgumentParser()
# xml文件的地址,根据自己的数据进行修改 xml一般存放在Annotations下
parser.add_argument('--xml_path', default='Annotations/', type=str, help='input xml label path')
# 数据集的划分,地址选择自己数据下的ImageSets/Main
parser.add_argument('--txt_path', default='ImageSets/Main/', type=str, help='output txt label path')
opt = parser.parse_args()

train_percent = 0.8  # 训练集所占比例
val_percent = 0.1    # 验证集所占比例
test_persent = 0.1   # 测试集所占比例

xmlfilepath = opt.xml_path
txtsavepath = opt.txt_path
total_xml = os.listdir(xmlfilepath)

if not os.path.exists(txtsavepath):
    os.makedirs(txtsavepath)

num = len(total_xml)  
list = list(range(num))

t_train = int(num * train_percent)  
t_val = int(num * val_percent)

train = random.sample(list, t_train)
num1 = len(train)
for i in range(num1):
    list.remove(train[i])


val_test = [i for i in list if not i in train]
val = random.sample(val_test, t_val)
num2 = len(val)
for i in range(num2):
    list.remove(val[i])


file_train = open(txtsavepath + '/train.txt', 'w')
file_val = open(txtsavepath + '/val.txt', 'w')
file_test = open(txtsavepath + '/test.txt', 'w')

for i in train:
    name = total_xml[i][:-4] + '\n'
    file_train.write(name)

for i in val:
    name = total_xml[i][:-4] + '\n'
    file_val.write(name)    

for i in list:
    name = total_xml[i][:-4] + '\n'
    file_test.write(name)
    
    
file_train.close()
file_val.close()
file_test.close()
  • voc转label得到label文件

目录结构如下:

└─VOC2028:		自定义数据集
    ├─Annotations	存放的是数据集标签文件,xml格式
    ├─ImageSets		数据集的划分文件
    │  └─Main
    ├─JPEGImages	存放的是数据集图片
    └─labels		yolov5将此文件夹当作训练的标注文件夹
└─voc_label.py

voc_label.py文件代码如下

# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import os

sets = ['train', 'val', 'test']  # 如果你的Main文件夹没有test.txt,就删掉'test'
classes = ["hat", "people"]   # 改成自己的类别,VOC数据集有以下20类别
# classes = ["brickwork", "coil","rebar"]   # 改成自己的类别,VOC数据集有以下20类别
# classes = ["aeroplane", 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog',
#            'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']  # class names
# abs_path = os.getcwd() /root/yolov5/data/voc_label.py 
abs_path = '/root/yolov5/data/'

def convert(size, box):
    dw = 1. / (size[0])
    dh = 1. / (size[1])
    x = (box[0] + box[1]) / 2.0 - 1
    y = (box[2] + box[3]) / 2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh
    return x, y, w, h


def convert_annotation(image_id):
    in_file = open(abs_path + '/VOC2028/Annotations/%s.xml' % (image_id), encoding='UTF-8')
    out_file = open(abs_path + '/VOC2028/labels/%s.txt' % (image_id), 'w')
    tree = ET.parse(in_file)
    root = tree.getroot()
    size = root.find('size')
    w = int(size.find('width').text)
    h = int(size.find('height').text)
    for obj in root.iter('object'):
        difficult = obj.find('difficult').text
        # difficult = obj.find('Difficult').text
        cls = obj.find('name').text
        if cls not in classes or int(difficult) == 1:
            continue
        cls_id = classes.index(cls)
        xmlbox = obj.find('bndbox')
        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
             float(xmlbox.find('ymax').text))
        b1, b2, b3, b4 = b
        # 标注越界修正
        if b2 > w:
            b2 = w
        if b4 > h:
            b4 = h
        b = (b1, b2, b3, b4)
        bb = convert((w, h), b)
        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')


for image_set in sets:
    if not os.path.exists(abs_path + '/VOC2028/labels/'):
        os.makedirs(abs_path + '/VOC2028/labels/')

    image_ids = open(abs_path + '/VOC2028/ImageSets/Main/%s.txt' % (image_set)).read().strip().split()
    list_file = open(abs_path + '/VOC2028/%s.txt' % (image_set), 'w')
    for image_id in image_ids:
        list_file.write(abs_path + '/VOC2028/JPEGImages/%s.jpg\n' % (image_id))  # 要么自己补全路径,只写一半可能会报错
        convert_annotation(image_id)
    list_file.close()


picture 1

图1 文件列表图

训练模型

  • 配置环境
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt
pip install onnx
  • 下载预训练权重(博主尝试了v7.0的和v6.0的pt都可以)
https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt

picture 0

图2 官方模型pt图
  • 训练(博主使用的是学校的集群进行训练)
python3 train.py --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --data data/safthat.yaml --epochs 150 --batch-size 16 --multi-scale --device 0 

picture 2

图3 模型训练
python3 detect.py --source /root/yolov5/data/images/000000.jpg --weights /root/yolov5/runs/train/exp13/weights/best.pt --conf-thres 0.25

picture 3

图4 安全帽模型测试

自定义yolov5s pt模型进行转换(干货)

下载瑞芯微官方修改过的yolov5以及环境搭建

本人使用的是conda进行的处理,首先先拉取仓库,然后安装conda(可以参考该文章),我使用的是python3.8。

具体执行:

git clone https://github.com/airockchip/yolov5.git
(www) C:\Users\wxw>cd C:\Users\wxw\PycharmProjects\yolov5
在conda终端配置镜像源
conda config --remove-key channels
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
(www) C:\Users\wxw\PycharmProjects\yolov5>pip install -r requirements.txt

输出结果成功安装:

Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting gitpython (from -r requirements.txt (line 5))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/1d/9a/4114a9057db2f1462d5c8f8390ab7383925fe1ac012eaa42402ad65c2963/GitPython-3.1.44-py3-none-any.whl (207 kB)
Collecting ipython (from -r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/8d/97/8fe103906cd81bc42d3b0175b5534a9f67dccae47d6451131cf8d0d70bb2/ipython-8.12.3-py3-none-any.whl (798 kB)
Collecting matplotlib>=3.2.2 (from -r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/16/51/58b0b9de42fe1e665736d9286f88b5f1556a0e22bed8a71f468231761083/matplotlib-3.7.5-cp38-cp38-win_amd64.whl (7.5 MB)
Collecting numpy>=1.18.5 (from -r requirements.txt (line 8))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/69/65/0d47953afa0ad569d12de5f65d964321c208492064c38fe3b0b9744f8d44/numpy-1.24.4-cp38-cp38-win_amd64.whl (14.9 MB)
Collecting opencv-python>=4.1.1 (from -r requirements.txt (line 9))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/a4/7d/f1c30a92854540bf789e9cd5dde7ef49bbe63f855b85a2e6b3db8135c591/opencv_python-4.11.0.86-cp37-abi3-win_amd64.whl (39.5 MB)
Collecting Pillow>=7.1.2 (from -r requirements.txt (line 10))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/f2/75/3cb820b2812405fc7feb3d0deb701ef0c3de93dc02597115e00704591bc9/pillow-10.4.0-cp38-cp38-win_amd64.whl (2.6 MB)
Collecting psutil (from -r requirements.txt (line 11))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/7b/d7/7831438e6c3ebbfa6e01a927127a6cb42ad3ab844247f3c5b96bea25d73d/psutil-6.1.1-cp37-abi3-win_amd64.whl (254 kB)
Collecting PyYAML>=5.3.1 (from -r requirements.txt (line 12))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/75/8a/ee831ad5fafa4431099aa4e078d4c8efd43cd5e48fbc774641d233b683a9/PyYAML-6.0.2-cp38-cp38-win_amd64.whl (162 kB)
Collecting requests>=2.23.0 (from -r requirements.txt (line 13))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/f9/9b/335f9764261e915ed497fcdeb11df5dfd6f7bf257d4a6a2a686d80da4d54/requests-2.32.3-py3-none-any.whl (64 kB)
Collecting scipy>=1.4.1 (from -r requirements.txt (line 14))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/32/8e/7f403535ddf826348c9b8417791e28712019962f7e90ff845896d6325d09/scipy-1.10.1-cp38-cp38-win_amd64.whl (42.2 MB)
Collecting thop>=0.1.1 (from -r requirements.txt (line 15))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/bb/0f/72beeab4ff5221dc47127c80f8834b4bcd0cb36f6ba91c0b1d04a1233403/thop-0.1.1.post2209072238-py3-none-any.whl (15 kB)
Collecting torch>=1.7.0 (from -r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/9d/58/37166e7f71cd35e7f76d462fa058758a0aa6c31c1a7e26290f7898d37360/torch-2.4.1-cp38-cp38-win_amd64.whl (199.4 MB)
Collecting torchvision>=0.8.1 (from -r requirements.txt (line 17))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/f6/4e/17d3137e893e878d2c165268b3f80d59e306e1ac1e0d89d8cccb27cc1d76/torchvision-0.19.1-cp38-cp38-win_amd64.whl (1.3 MB)
Collecting tqdm>=4.64.0 (from -r requirements.txt (line 18))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/d0/30/dc54f88dd4a2b5dc8a0279bdd7270e735851848b762aeb1c1184ed1f6b14/tqdm-4.67.1-py3-none-any.whl (78 kB)
Collecting tensorboard>=2.4.1 (from -r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/bc/a2/ff5f4c299eb37c95299a76015da3f30211468e29d8d6f1d011683279baee/tensorboard-2.14.0-py3-none-any.whl (5.5 MB)
Collecting pandas>=1.1.4 (from -r requirements.txt (line 27))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/c3/6c/ea362eef61f05553aaf1a24b3e96b2d0603f5dc71a3bd35688a24ed88843/pandas-2.0.3-cp38-cp38-win_amd64.whl (10.8 MB)
Collecting seaborn>=0.11.0 (from -r requirements.txt (line 28))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/83/11/00d3c3dfc25ad54e731d91449895a79e4bf2384dc3ac01809010ba88f6d5/seaborn-0.13.2-py3-none-any.whl (294 kB)
Collecting gitdb<5,>=4.0.1 (from gitpython->-r requirements.txt (line 5))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/a0/61/5c78b91c3143ed5c14207f463aecfc8f9dbb5092fb2869baf37c273b2705/gitdb-4.0.12-py3-none-any.whl (62 kB)
Collecting backcall (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/4c/1c/ff6546b6c12603d8dd1070aa3c3d273ad4c07f5771689a7b69a550e8c951/backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Collecting decorator (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/d5/50/83c593b07763e1161326b3b8c6686f0f4b0f24d5526546bee538c89837d6/decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting jedi>=0.16 (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/c0/5a/9cac0c82afec3d09ccd97c8b6502d48f165f9124db81b4bcb90b4af974ee/jedi-0.19.2-py2.py3-none-any.whl (1.6 MB)
Collecting matplotlib-inline (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/8f/8e/9ad090d3553c280a8060fbf6e24dc1c0c29704ee7d1c372f0c174aa59285/matplotlib_inline-0.1.7-py3-none-any.whl (9.9 kB)
Collecting pickleshare (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl (6.9 kB)
Collecting prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30 (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/e4/ea/d836f008d33151c7a1f62caf3d8dd782e4d15f6a43897f64480c2b8de2ad/prompt_toolkit-3.0.50-py3-none-any.whl (387 kB)
Collecting pygments>=2.4.0 (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/8a/0b/9fcc47d19c48b59121088dd6da2488a49d5f72dacf8262e2790a1d2c7d15/pygments-2.19.1-py3-none-any.whl (1.2 MB)
Collecting stack-data (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/f1/7b/ce1eafaf1a76852e2ec9b22edecf1daa58175c090266e9f6c64afcd81d91/stack_data-0.6.3-py3-none-any.whl (24 kB)
Collecting traitlets>=5 (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/00/c0/8f5d070730d7836adc9c9b6408dec68c6ced86b304a9b26a14df072a6e8c/traitlets-5.14.3-py3-none-any.whl (85 kB)
Collecting typing-extensions (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Collecting colorama (from ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting contourpy>=1.0.1 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/96/1b/b05cd42c8d21767a0488b883b38658fb9a45f86c293b7b42521a8113dc5d/contourpy-1.1.1-cp38-cp38-win_amd64.whl (477 kB)
Collecting cycler>=0.10 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/e7/05/c19819d5e3d95294a6f5947fb9b9629efb316b96de511b418c53d245aae6/cycler-0.12.1-py3-none-any.whl (8.3 kB)
Collecting fonttools>=4.22.0 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/00/3a/9dcfa83d97b6ebb717f7da1fd8dcd745a15bd5378863742732110b9c9499/fonttools-4.55.8-cp38-cp38-win_amd64.whl (1.5 MB)
Collecting kiwisolver>=1.0.1 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/52/77/7e04cca2ff1dc6ee6b7654cebe233de72b7a3ec5616501b6f3144fb70740/kiwisolver-1.4.7-cp38-cp38-win_amd64.whl (55 kB)
Collecting packaging>=20.0 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl (65 kB)
Collecting pyparsing>=2.3.1 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/e5/0c/0e3c05b1c87bb6a1c76d281b0f35e78d2d80ac91b5f8f524cebf77f51049/pyparsing-3.1.4-py3-none-any.whl (104 kB)
Collecting python-dateutil>=2.7 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
Collecting importlib-resources>=3.2.0 (from matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/e1/6a/4604f9ae2fa62ef47b9de2fa5ad599589d28c9fd1d335f32759813dfa91e/importlib_resources-6.4.5-py3-none-any.whl (36 kB)
Collecting charset-normalizer<4,>=2 (from requests>=2.23.0->-r requirements.txt (line 13))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/40/bb/20affbbd9ea29c71ea123769dc568a6d42052ff5089c5fe23e21e21084a6/charset_normalizer-3.4.1-cp38-cp38-win_amd64.whl (102 kB)
Collecting idna<4,>=2.5 (from requests>=2.23.0->-r requirements.txt (line 13))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl (70 kB)
Collecting urllib3<3,>=1.21.1 (from requests>=2.23.0->-r requirements.txt (line 13))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/ce/d9/5f4c13cecde62396b0d3fe530a50ccea91e7dfc1ccf0e09c228841bb5ba8/urllib3-2.2.3-py3-none-any.whl (126 kB)
Collecting certifi>=2017.4.17 (from requests>=2.23.0->-r requirements.txt (line 13))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/38/fc/bce832fd4fd99766c04d1ee0eead6b0ec6486fb100ae5e74c1d91292b982/certifi-2025.1.31-py3-none-any.whl (166 kB)
Collecting filelock (from torch>=1.7.0->-r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/b9/f8/feced7779d755758a52d1f6635d990b8d98dc0a29fa568bbe0625f18fdf3/filelock-3.16.1-py3-none-any.whl (16 kB)
Collecting sympy (from torch>=1.7.0->-r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/99/ff/c87e0622b1dadea79d2fb0b25ade9ed98954c9033722eb707053d310d4f3/sympy-1.13.3-py3-none-any.whl (6.2 MB)
Collecting networkx (from torch>=1.7.0->-r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/a8/05/9d4f9b78ead6b2661d6e8ea772e111fc4a9fbd866ad0c81906c11206b55e/networkx-3.1-py3-none-any.whl (2.1 MB)
Collecting jinja2 (from torch>=1.7.0->-r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/bd/0f/2ba5fbcd631e3e88689309dbe978c5769e883e4b84ebfe7da30b43275c5a/jinja2-3.1.5-py3-none-any.whl (134 kB)
Collecting fsspec (from torch>=1.7.0->-r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/e2/94/758680531a00d06e471ef649e4ec2ed6bf185356a7f9fbfbb7368a40bd49/fsspec-2025.2.0-py3-none-any.whl (184 kB)
Collecting absl-py>=0.4 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/a2/ad/e0d3c824784ff121c03cc031f944bc7e139a8f1870ffd2845cc2dd76f6c4/absl_py-2.1.0-py3-none-any.whl (133 kB)
Collecting grpcio>=1.48.2 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/87/7d/36009c38093e62969c708f20b86ab6761c2ba974b12ff10def6f397f24fa/grpcio-1.70.0-cp38-cp38-win_amd64.whl (4.3 MB)
Collecting google-auth<3,>=1.6.3 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/9d/47/603554949a37bca5b7f894d51896a9c534b9eab808e2520a748e081669d0/google_auth-2.38.0-py2.py3-none-any.whl (210 kB)
Collecting google-auth-oauthlib<1.1,>=0.5 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/4a/07/8d9a8186e6768b55dfffeb57c719bc03770cf8a970a074616ae6f9e26a57/google_auth_oauthlib-1.0.0-py2.py3-none-any.whl (18 kB)
Collecting markdown>=2.6.8 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/3f/08/83871f3c50fc983b88547c196d11cf8c3340e37c32d2e9d6152abe2c61f7/Markdown-3.7-py3-none-any.whl (106 kB)
Collecting protobuf>=3.19.6 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/c6/36/37425a115a95e35a1d8dff686ac2488718a40f07d498edfd89eb40ee3c5d/protobuf-5.29.3-cp38-cp38-win_amd64.whl (434 kB)
Requirement already satisfied: setuptools>=41.0.0 in c:\users\wxw\.conda\envs\www\lib\site-packages (from tensorboard>=2.4.1->-r requirements.txt (line 22)) (75.1.0)
Collecting tensorboard-data-server<0.8.0,>=0.7.0 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/7a/13/e503968fefabd4c6b2650af21e110aa8466fe21432cd7c43a84577a89438/tensorboard_data_server-0.7.2-py3-none-any.whl (2.4 kB)
Collecting werkzeug>=1.0.1 (from tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/6c/69/05837f91dfe42109203ffa3e488214ff86a6d68b2ed6c167da6cdc42349b/werkzeug-3.0.6-py3-none-any.whl (227 kB)
Requirement already satisfied: wheel>=0.26 in c:\users\wxw\.conda\envs\www\lib\site-packages (from tensorboard>=2.4.1->-r requirements.txt (line 22)) (0.44.0)
Collecting pytz>=2020.1 (from pandas>=1.1.4->-r requirements.txt (line 27))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/eb/38/ac33370d784287baa1c3d538978b5e2ea064d4c1b93ffbd12826c190dd10/pytz-2025.1-py2.py3-none-any.whl (507 kB)
Collecting tzdata>=2022.1 (from pandas>=1.1.4->-r requirements.txt (line 27))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/0f/dd/84f10e23edd882c6f968c21c2434fe67bd4a528967067515feca9e611e5e/tzdata-2025.1-py2.py3-none-any.whl (346 kB)
Collecting smmap<6,>=3.0.1 (from gitdb<5,>=4.0.1->gitpython->-r requirements.txt (line 5))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/04/be/d09147ad1ec7934636ad912901c5fd7667e1c858e19d355237db0d0cd5e4/smmap-5.0.2-py3-none-any.whl (24 kB)
Collecting cachetools<6.0,>=2.0.0 (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/ec/4e/de4ff18bcf55857ba18d3a4bd48c8a9fde6bb0980c9d20b263f05387fd88/cachetools-5.5.1-py3-none-any.whl (9.5 kB)
Collecting pyasn1-modules>=0.2.1 (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/77/89/bc88a6711935ba795a679ea6ebee07e128050d6382eaa35a0a47c8032bdc/pyasn1_modules-0.4.1-py3-none-any.whl (181 kB)
Collecting rsa<5,>=3.1.4 (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/49/97/fa78e3d2f65c02c8e1268b9aba606569fe97f6c8f7c2d74394553347c145/rsa-4.9-py3-none-any.whl (34 kB)
Collecting requests-oauthlib>=0.7.0 (from google-auth-oauthlib<1.1,>=0.5->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/3b/5d/63d4ae3b9daea098d5d6f5da83984853c1bbacd5dc826764b249fe119d24/requests_oauthlib-2.0.0-py2.py3-none-any.whl (24 kB)
Collecting zipp>=3.1.0 (from importlib-resources>=3.2.0->matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/62/8b/5ba542fa83c90e09eac972fc9baca7a88e7e7ca4b221a89251954019308b/zipp-3.20.2-py3-none-any.whl (9.2 kB)
Collecting parso<0.9.0,>=0.8.4 (from jedi>=0.16->ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/c6/ac/dac4a63f978e4dcb3c6d3a78c4d8e0192a113d288502a1216950c41b1027/parso-0.8.4-py2.py3-none-any.whl (103 kB)
Collecting importlib-metadata>=4.4 (from markdown>=2.6.8->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/a0/d9/a1e041c5e7caa9a05c925f4bdbdfb7f006d1f74996af53467bc394c97be7/importlib_metadata-8.5.0-py3-none-any.whl (26 kB)
Collecting wcwidth (from prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30->ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/fd/84/fd2ba7aafacbad3c4201d395674fc6348826569da3c0937e75505ead3528/wcwidth-0.2.13-py2.py3-none-any.whl (34 kB)
Collecting six>=1.5 (from python-dateutil>=2.7->matplotlib>=3.2.2->-r requirements.txt (line 7))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB)
Collecting MarkupSafe>=2.1.1 (from werkzeug>=1.0.1->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/92/21/357205f03514a49b293e214ac39de01fadd0970a6e05e4bf1ddd0ffd0881/MarkupSafe-2.1.5-cp38-cp38-win_amd64.whl (17 kB)
Collecting executing>=1.2.0 (from stack-data->ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/7b/8f/c4d9bafc34ad7ad5d8dc16dd1347ee0e507a52c3adb6bfa8887e1c6a26ba/executing-2.2.0-py2.py3-none-any.whl (26 kB)
Collecting asttokens>=2.1.0 (from stack-data->ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/25/8a/c46dcc25341b5bce5472c718902eb3d38600a903b14fa6aeecef3f21a46f/asttokens-3.0.0-py3-none-any.whl (26 kB)
Collecting pure-eval (from stack-data->ipython->-r requirements.txt (line 6))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/8e/37/efad0257dc6e593a18957422533ff0f87ede7c9c6ea010a2177d738fb82f/pure_eval-0.2.3-py3-none-any.whl (11 kB)
Collecting mpmath<1.4,>=1.1.0 (from sympy->torch>=1.7.0->-r requirements.txt (line 16))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/43/e3/7d92a15f894aa0c9c4b49b8ee9ac9850d6e63b03c9c32c0367a13ae62209/mpmath-1.3.0-py3-none-any.whl (536 kB)
Collecting pyasn1<0.7.0,>=0.4.6 (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/c8/f1/d6a797abb14f6283c0ddff96bbdd46937f64122b8c925cab503dd37f8214/pyasn1-0.6.1-py3-none-any.whl (83 kB)
Collecting oauthlib>=3.0.0 (from requests-oauthlib>=0.7.0->google-auth-oauthlib<1.1,>=0.5->tensorboard>=2.4.1->-r requirements.txt (line 22))
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/7e/80/cab10959dc1faead58dc8384a781dfbf93cb4d33d50988f7a69f1b7c9bbe/oauthlib-3.2.2-py3-none-any.whl (151 kB)
Installing collected packages: wcwidth, pytz, pure-eval, pickleshare, mpmath, backcall, zipp, urllib3, tzdata, typing-extensions, traitlets, tensorboard-data-server, sympy, smmap, six, PyYAML, pyparsing, pygments, pyasn1, psutil, protobuf, prompt-toolkit, Pillow, parso, packaging, oauthlib, numpy, networkx, MarkupSafe, kiwisolver, idna, grpcio, fsspec, fonttools, filelock, executing, decorator, cycler, colorama, charset-normalizer, certifi, cachetools, asttokens, absl-py, werkzeug, tqdm, stack-data, scipy, rsa, requests, python-dateutil, pyasn1-modules, opencv-python, matplotlib-inline, jinja2, jedi, importlib-resources, importlib-metadata, gitdb, contourpy, torch, requests-oauthlib, pandas, matplotlib, markdown, ipython, google-auth, gitpython, torchvision, thop, seaborn, google-auth-oauthlib, tensorboard
Successfully installed MarkupSafe-2.1.5 Pillow-10.4.0 PyYAML-6.0.2 absl-py-2.1.0 asttokens-3.0.0 backcall-0.2.0 cachetools-5.5.1 certifi-2025.1.31 charset-normalizer-3.4.1 colorama-0.4.6 contourpy-1.1.1 cycler-0.12.1 decorator-5.1.1 executing-2.2.0 filelock-3.16.1 fonttools-4.55.8 fsspec-2025.2.0 gitdb-4.0.12 gitpython-3.1.44 google-auth-2.38.0 google-auth-oauthlib-1.0.0 grpcio-1.70.0 idna-3.10 importlib-metadata-8.5.0 importlib-resources-6.4.5 ipython-8.12.3 jedi-0.19.2 jinja2-3.1.5 kiwisolver-1.4.7 markdown-3.7 matplotlib-3.7.5 matplotlib-inline-0.1.7 mpmath-1.3.0 networkx-3.1 numpy-1.24.4 oauthlib-3.2.2 opencv-python-4.11.0.86 packaging-24.2 pandas-2.0.3 parso-0.8.4 pickleshare-0.7.5 prompt-toolkit-3.0.50 protobuf-5.29.3 psutil-6.1.1 pure-eval-0.2.3 pyasn1-0.6.1 pyasn1-modules-0.4.1 pygments-2.19.1 pyparsing-3.1.4 python-dateutil-2.9.0.post0 pytz-2025.1 requests-2.32.3 requests-oauthlib-2.0.0 rsa-4.9 scipy-1.10.1 seaborn-0.13.2 six-1.17.0 smmap-5.0.2 stack-data-0.6.3 sympy-1.13.3 tensorboard-2.14.0 tensorboard-data-server-0.7.2 thop-0.1.1.post2209072238 torch-2.4.1 torchvision-0.19.1 tqdm-4.67.1 traitlets-5.14.3 typing-extensions-4.12.2 tzdata-2025.1 urllib3-2.2.3 wcwidth-0.2.13 werkzeug-3.0.6 zipp-3.20.2

picture 1

图5 conda ui界面

模型转换为onnx(和官方yolov5不同所以得用瑞芯微修改后的yolov5)

conda终端执行命令

python export.py --rknpu --weight yolov5s.pt

输出结果如下,可以看到有一个报错ONNX: export failure 23.0s: DLL load failed while importing onnx_cpp2py_export: (DLL),该报错的解决办法可以将版本降低为1.61.1即可解决,最终得到优化后的onnx文件。

(www) C:\Users\wxw\PycharmProjects\yolov5>python export.py --rknpu --weight yolov5s_hat.pt
export: data=C:\Users\wxw\PycharmProjects\yolov5\data\coco128.yaml, weights=['yolov5s_hat.pt'], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx'], rknpu=True
YOLOv5  2023-12-19 Python-3.8.20 torch-2.4.1+cpu CPU

C:\Users\wxw\PycharmProjects\yolov5\models\experimental.py:80: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  ckpt = torch.load(attempt_download(w), map_location='cpu')  # load
Fusing layers...
YOLOv5s summary: 213 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs
---> save anchors for RKNN
[[10.0, 13.0], [16.0, 30.0], [33.0, 23.0], [30.0, 61.0], [62.0, 45.0], [59.0, 119.0], [116.0, 90.0], [156.0, 198.0], [373.0, 326.0]]
export detect model for RKNPU

PyTorch: starting from yolov5s_hat.pt with output shape (1, 21, 80, 80) (13.7 MB)
requirements: YOLOv5 requirement "onnx" not found, attempting AutoUpdate...
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting onnx
  Using cached https://mirrors.ustc.edu.cn/pypi/packages/2d/c8/5cc6f2c7b33547099506dcee04ab3c2dafc4f2f034d67fc158a7bc0a2474/onnx-1.17.0-cp38-cp38-win_amd64.whl (14.5 MB)
Requirement already satisfied: numpy>=1.20 in c:\users\wxw\.conda\envs\www\lib\site-packages (from onnx) (1.24.4)
Requirement already satisfied: protobuf>=3.20.2 in c:\users\wxw\.conda\envs\www\lib\site-packages (from onnx) (5.29.3)
Installing collected packages: onnx
Successfully installed onnx-1.17.0

requirements: 1 package updated per ['onnx']
requirements:  Restart runtime or rerun command for updates to take effect

ONNX: export failure  23.0s: DLL load failed while importing onnx_cpp2py_export: (DLL)

(www) C:\Users\wxw\PycharmProjects\yolov5>pip install onnx==1.16.1
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting onnx==1.16.1
  Downloading https://mirrors.ustc.edu.cn/pypi/packages/5c/8d/7efe8c1f489cab37d45e7676d8c371c67d404dcad9e3b22ed5499e3a9ffb/onnx-1.16.1-cp38-cp38-win_amd64.whl (14.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.4/14.4 MB 20.2 MB/s eta 0:00:00
Requirement already satisfied: numpy>=1.20 in c:\users\wxw\.conda\envs\www\lib\site-packages (from onnx==1.16.1) (1.24.4)
Requirement already satisfied: protobuf>=3.20.2 in c:\users\wxw\.conda\envs\www\lib\site-packages (from onnx==1.16.1) (5.29.3)
Installing collected packages: onnx
  Attempting uninstall: onnx
    Found existing installation: onnx 1.17.0
    Uninstalling onnx-1.17.0:
      Successfully uninstalled onnx-1.17.0
Successfully installed onnx-1.16.1

(www) C:\Users\wxw\PycharmProjects\yolov5>python export.py --rknpu --weight yolov5s_hat.pt
export: data=C:\Users\wxw\PycharmProjects\yolov5\data\coco128.yaml, weights=['yolov5s_hat.pt'], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx'], rknpu=True
YOLOv5  2023-12-19 Python-3.8.20 torch-2.4.1+cpu CPU

C:\Users\wxw\PycharmProjects\yolov5\models\experimental.py:80: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  ckpt = torch.load(attempt_download(w), map_location='cpu')  # load
Fusing layers...
YOLOv5s summary: 213 layers, 7015519 parameters, 0 gradients, 15.8 GFLOPs
---> save anchors for RKNN
[[10.0, 13.0], [16.0, 30.0], [33.0, 23.0], [30.0, 61.0], [62.0, 45.0], [59.0, 119.0], [116.0, 90.0], [156.0, 198.0], [373.0, 326.0]]
export detect model for RKNPU

PyTorch: starting from yolov5s_hat.pt with output shape (1, 21, 80, 80) (13.7 MB)

ONNX: starting export with onnx 1.16.1...
ONNX: export success  1.2s, saved as yolov5s_hat.onnx (26.8 MB)

Export complete (2.2s)
Results saved to C:\Users\wxw\PycharmProjects\yolov5
Detect:          python detect.py --weights yolov5s_hat.onnx
Validate:        python val.py --weights yolov5s_hat.onnx
PyTorch Hub:     model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s_hat.onnx')
Visualize:       https://netron.app

(www) C:\Users\wxw\PycharmProjects\yolov5>

优化后的明显比之前的算子优化了很多。

picture 2

图6 模型onnx图

准备模型转换需要的文件

  • 量化数据集文件与文件路径

hat_subset.txt文件内容如下:

./subset/000032.jpg
./subset/000036.jpg
./subset/000076.jpg
./subset/000083.jpg

picture 3

图7 资源列表图
  • 准备模型与标签
    将上文得到的onnx模型放到model路径下,以及修改标签文件,准备一张安全帽的测试图片
    hat_label_list.txt内容如下:
hat
person

picture 4

图8 模型标签文件列表图
  • 修改生成的编译脚本
    要修改cmakelist其中的路径,cpp文件夹中postprocess的cc文件和h文件的类别,修改convert.py文件中数据集路径和生成rknn模型路径,如下图

picture 5

图9 修改1

picture 6

图10 修改2

picture 7

图11 修改3

picture 8

图12 修改4

量化转化得到rknn模型以及编译得到可执行文件

  • 转化模型
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/examples/yolov5/python# python3 ./convert.py ../model/yolov5s_hat.onnx rk3588
I rknn-toolkit2 version: 2.1.0+708089d1
--> Config model
done
--> Loading model
I Loading : 100%|██████████████████████████████████████████████| 121/121 [00:00<00:00, 11037.64it/s]
done
--> Building model
I OpFusing 0: 100%|██████████████████████████████████████████████| 100/100 [00:00<00:00, 358.08it/s]
I OpFusing 1 : 100%|█████████████████████████████████████████████| 100/100 [00:00<00:00, 269.36it/s]
I OpFusing 2 : 100%|██████████████████████████████████████████████| 100/100 [00:01<00:00, 77.88it/s]
I GraphPreparing : 100%|████████████████████████████████████████| 149/149 [00:00<00:00, 3244.53it/s]
I Quantizating : 100%|████████████████████████████████████████████| 149/149 [00:57<00:00,  2.60it/s]
W build: The default input dtype of 'images' is changed from 'float32' to 'int8' in rknn model for performance!
                       Please take care of this change when deploy rknn model with Runtime API!
W build: The default output dtype of 'output0' is changed from 'float32' to 'int8' in rknn model for performance!
                      Please take care of this change when deploy rknn model with Runtime API!
W build: The default output dtype of '367' is changed from 'float32' to 'int8' in rknn model for performance!
                      Please take care of this change when deploy rknn model with Runtime API!
W build: The default output dtype of '369' is changed from 'float32' to 'int8' in rknn model for performance!
                      Please take care of this change when deploy rknn model with Runtime API!
I rknn building ...
I rknn buiding done.
done
--> Export rknn model
done
  • 编译可执行文件并打包

执行和输出结果:

root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0# ./build-linux.sh -t rk3588 -a aarch64 -d yolov5
./build-linux.sh -t rk3588 -a aarch64 -d yolov5
/mnt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu
===================================
BUILD_DEMO_NAME=yolov5
BUILD_DEMO_PATH=examples/yolov5/cpp
TARGET_SOC=rk3588
TARGET_ARCH=aarch64
BUILD_TYPE=Release
ENABLE_ASAN=OFF
INSTALL_DIR=/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo
BUILD_DIR=/mnt/rknn_model_zoo-2.1.0/build/build_rknn_yolov5_demo_rk3588_linux_aarch64_Release
CC=/mnt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
CXX=/mnt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
===================================
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/rknn_model_zoo-2.1.0/build/build_rknn_yolov5_demo_rk3588_linux_aarch64_Release
[ 33%] Built target audioutils
[ 33%] Built target fileutils
[ 50%] Built target imageutils
[ 66%] Built target imagedrawing
Scanning dependencies of target rknn_yolov5_demo
[ 83%] Building CXX object CMakeFiles/rknn_yolov5_demo.dir/rknpu2/yolov5.cc.o
[ 83%] Building CXX object CMakeFiles/rknn_yolov5_demo.dir/main.cc.o
[ 91%] Building CXX object CMakeFiles/rknn_yolov5_demo.dir/postprocess.cc.o
/mnt/rknn_model_zoo-2.1.0/examples/yolov5/cpp/postprocess.cc: In function 'char* coco_cls_to_name(int)':
/mnt/rknn_model_zoo-2.1.0/examples/yolov5/cpp/postprocess.cc:577:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
         return "null";
                ^~~~~~
/mnt/rknn_model_zoo-2.1.0/examples/yolov5/cpp/postprocess.cc:585:12: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
     return "null";
            ^~~~~~
[100%] Linking CXX executable rknn_yolov5_demo
[100%] Built target rknn_yolov5_demo
[ 16%] Built target fileutils
[ 33%] Built target imageutils
[ 50%] Built target imagedrawing
[ 83%] Built target rknn_yolov5_demo
[100%] Built target audioutils
Install the project...
-- Install configuration: "Release"
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/./rknn_yolov5_demo
-- Set runtime path of "/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/./rknn_yolov5_demo" to "$ORIGIN/lib"
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/./model/hat.jpg
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/./model/hat_label_list.txt
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/model/yolov5.rknn
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/model/yolov5_hat.rknn
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/lib/librknnrt.so
-- Installing: /mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo/lib/librga.so
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0# cd install/
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install# ls
rk3588_linux_aarch64
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install# cd rk3588_linux_aarch64/
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# ls
rknn_yolov5_demo  rknn_yolov5_demo_hat_my.tar.gz
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# cd rknn_yolov5_demo
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo# ls
lib  model  rknn_yolov5_demo
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo# ls model/
hat.jpg  hat_label_list.txt  yolov5.rknn  yolov5_hat.rknn
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64/rknn_yolov5_demo# cd ..
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# ls
rknn_yolov5_demo  rknn_yolov5_demo_hat_my.tar.gz
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# rm -rf rknn_yolov5_demo_hat_my.tar.gz 
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# tar -zcvf rknn_yolov5_demo_try.tar.gz
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# tar -zcvf rknn_yolov5_demo_try.tar.gz rknn_yolov5_demo/
rknn_yolov5_demo/
rknn_yolov5_demo/model/
rknn_yolov5_demo/model/hat.jpg
rknn_yolov5_demo/model/hat_label_list.txt
rknn_yolov5_demo/model/yolov5.rknn
rknn_yolov5_demo/model/yolov5_hat.rknn
rknn_yolov5_demo/lib/
rknn_yolov5_demo/lib/librknnrt.so
rknn_yolov5_demo/lib/librga.so
rknn_yolov5_demo/rknn_yolov5_demo
root@5c542f109d4c:/mnt/rknn_model_zoo-2.1.0/install/rk3588_linux_aarch64# 

上机测试

  • 拷贝解压执行文件及其输出结果:
root@elf2-desktop:~# tar -zxvf rknn_yolov5_demo_try.tar.gz
rknn_yolov5_demo/
rknn_yolov5_demo/model/
rknn_yolov5_demo/model/hat.jpg
rknn_yolov5_demo/model/hat_label_list.txt
rknn_yolov5_demo/model/yolov5.rknn
rknn_yolov5_demo/model/yolov5_hat.rknn
rknn_yolov5_demo/lib/
rknn_yolov5_demo/lib/librknnrt.so
rknn_yolov5_demo/lib/librga.so
rknn_yolov5_demo/rknn_yolov5_demo
root@elf2-desktop:~# cd rknn_yolov5_demo
root@elf2-desktop:~/rknn_yolov5_demo# ls
lib  model  rknn_yolov5_demo
root@elf2-desktop:~/rknn_yolov5_demo# chmod 777 rknn_yolov5_demo
root@elf2-desktop:~/rknn_yolov5_demo# ls
lib  model  rknn_yolov5_demo
root@elf2-desktop:~/rknn_yolov5_demo# ./rknn_yolov5_demo model/yolov5_hat.rknn model/hat.jpg
load lable ./model/hat_label_list.txt
model input num: 1, output num: 3
input tensors:
  index=0, name=images, n_dims=4, dims=[1, 640, 640, 3], n_elems=1228800, size=1228800, fmt=NHWC, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
output tensors:
  index=0, name=output0, n_dims=4, dims=[1, 21, 80, 80], n_elems=134400, size=134400, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
  index=1, name=367, n_dims=4, dims=[1, 21, 40, 40], n_elems=33600, size=33600, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
  index=2, name=369, n_dims=4, dims=[1, 21, 20, 20], n_elems=8400, size=8400, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
model is NHWC input fmt
model input height=640, width=640, channel=3
origin size=640x640 crop size=640x640
input image: 640 x 640, subsampling: 4:2:0, colorspace: YCbCr, orientation: 1
scale=1.000000 dst_box=(0 0 639 639) allow_slight_change=1 _left_offset=0 _top_offset=0 padding_w=0 padding_h=0
src width=640 height=640 fmt=0x1 virAddr=0x0x25720530 fd=0
dst width=640 height=640 fmt=0x1 virAddr=0x0x2584c540 fd=0
src_box=(0 0 639 639)
dst_box=(0 0 639 639)
color=0x72
rga_api version 1.10.1_[0]
rknn_run
hat @ (130 31 517 513) 0.867
write_image path: out.png width=640 height=640 channel=3 data=0x25720530
root@elf2-desktop:~/rknn_yolov5_demo#

  • 上机测试结果:

picture 0

图13 测试结果图

http://www.kler.cn/a/532276.html

相关文章:

  • 毕业设计:基于深度学习的高压线周边障碍物自动识别与监测系统
  • mysql 学习8 函数,字符串函数,数值函数,日期函数,流程函数
  • 想品客老师的第十一天:模块化开发
  • 机试题——字符匹配
  • Node.js常用知识
  • Day33【AI思考】-分层递进式结构 对数学数系的 终极系统分类
  • 出现 Can not find ‘Converter‘ support class Year 解决方法
  • UE学习日志#20 C++笔记#6 基础复习6 引用2
  • celery策略回测任务运行及金融量化数据增量更新|年化18.8%,回撤8%的组合策略(python代码)
  • python学习笔记5-函数的定义
  • 2022ACMToG | 寻找快速的去马赛克算法
  • 每天学点小知识之设计模式的艺术-策略模式
  • 网络安全学习 day5
  • 司库信息化解决方案(deepseek来源)
  • DeepSeek 遭 DDoS 攻击背后:DDoS 攻击的 “千层套路” 与安全防御 “金钟罩”_deepseek ddos
  • 11. 9 构建生产级聊天对话记忆系统:从架构设计到性能优化的全链路指南
  • 低空经济火热,大载重物流运输无人机技术详解
  • TensorFlow 与 PyTorch 的直观区别
  • sql表的增删改、替换
  • 扩展域并查集 带权并查集
  • 【PyQt】pyqt小案例实现简易文本编辑器
  • 【Leetcode刷题记录】1456. 定长子串中元音的最大数目---定长滑动窗口即解题思路总结
  • 代码随想录八股训练营学习总结
  • 哈希(Hashing)在 C++ STL 中的应用
  • 虚幻基础17:动画蓝图
  • 网站快速收录:如何优化网站长尾关键词布局?