Teach you how to deploy Baidu Flying Paddle PP-YOLOE to Rockchip RK3588

Table of contents

foreword

1. Environment construction

1. Anaconda3 installation

1.1. Download

1.2. Installation

2. Paddle model export environment

2.1. Create environment

2.2, enter the environment

2.3, paddle installation

2.4, Paddle Detection installation

 2.5. Solve related dependency problems

3. Paddle to onnx to rknn environment

3.1. Create environment

3.2, enter the environment

3.3, RKNN-Toolkit2 tool installation

3.3, paddle2onnx tool installation

3.4. Solve related dependency problems

2. Model conversion

1. Model export

2. paddle to onnx

3. Onnx to rknn

3. Run the routine


foreword

        PP-YOLOE is a target detection model released by Baidu Flying Paddle team. PP-YOLOE is an excellent single-stage anchor-free model based on PP-YOLOv2, which surpasses many popular YOLO models. PP-YOLOE has a series of models, namely s/m/l/x, which can be configured by width multiplier and depth multiplier. PP-YOLOE avoids the use of special operators such as Deformable Convolution or Matrix NMS, so that it can be easily deployed on a variety of hardware. RK3588 is a
        new generation of high-performance flagship Soc chip released by Rockchip, using ARM architecture, adopts advanced 8nm process technology, integrates quad-core Cortex-A76 and quad-core Cortex-A55 (8 cores in total), and a separate NEON coprocessor, supports 8K video codec, and integrates an independent NPU processor , can provide up to 6TOPS computing power, can meet the edge computing needs of most terminal devices, provide many powerful embedded hardware engines, provide extreme performance for high-end applications, and provide rich functional interfaces to meet Product customization needs of different industries.
        This article focuses on how to deploy the Baidu Flying Paddle PP-YOLOE model to Rockchip RK3588, including: environment construction, model conversion, and running routines. In addition, the difficulty of the entire deployment process lies in model conversion. The overall framework of model conversion is as follows:

The paddle model cannot be directly converted to Rockchip’s rknn format, so the paddle model must be converted to onnx first, and then onnx to rknn.

1. Environment construction

        System: Ubuntu18.04.5 (x64)
        User: root
        During the deployment process, the environment required by the operation under different steps will be different, and there may even be some software package version conflicts, so conda is used here for environment management.

1. Anaconda3 installation

1.1. Download

        Tsinghua mirror official website download address: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Download
        Anaconda3-2022.10-Linux-x86_64.sh here

1.2. Installation

        Install using the bash command:

# bash Anaconda3-2022.10-Linux-x86_64.sh

        Then enter yes all the way and press Enter. By default, a folder named anaconda3 is created in the user's home directory as the installation address. The root account is used here, so it is installed in the /root/anaconda3 directory.
        Interpretation of a prompt that appears after the Anaconda installation is complete:
        (1) For changes to take effect, close and re-open your current shell., the translation is: close the current command line and reopen it, just install and initialize the Anaconda settings After taking effect, reopen a command line and directly enter the base environment of conda.
        (2) If you'd prefer that conda's base environment not be activated on startup, set the auto_activate_base parameter to false: , the translation is: If you want conda's base environment not to be activated at startup, please set the auto_activate_base parameter to false, the command is as follows:

# conda config --set auto_activate_base false

        Of course, after this command is executed, if you want to enter the conda base environment again, you only need to use the corresponding conda command, as follows:

# conda activate base

        At this point, Anaconda3 is installed.

2. Paddle model export environment

        PP-YOLOE is the target detection model of Baidu Flying Paddle paddle. The export of the paddle target detection model depends on PaddleDetection, so the PaddleDetection toolkit must be installed. The reason why this environment needs to be built separately is because the onnx, numpy and other software package versions that the PaddleDetection tool depends on are not compatible with the rknn-toolkit2 of Rising Micro RK3588.
        PaddleDetection Version: 2.5.0
        rknn-toolkit2 Version: 1.3.0

2.1. Create environment

        Select the python3.8.13 package to create the environment, the command is as follows:

# conda create --name paddleExport python==3.8.13

2.2, enter the environment

        The command is as follows:

# conda activate paddleExport

        Note: Unless otherwise specified, all operations below in this chapter are performed in the created environment.

2.3, paddle installation

        Install the paddle package before installing the PaddleDetection tool. Use the Tsinghua University open source software mirror station to install the paddle package. Address: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/
        You can check the following items before installing Version dependent library:

# conda search --full-name paddlepaddle --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ --info

        Here select the cpu version of 2.3.2 for installation:

# conda install paddlepaddle=2.3.2 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/

        Verify installation:

        Enter python and press Enter to enter the python interpreter, enter import paddle, and then enter paddle.utils.run_check(). If PaddlePaddle is installed successfully! appears, it means it has been installed successfully.

(paddleExport) root@micro:~# python
Python 3.8.13 (default, Oct 21 2022, 23:50:54) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paddle
>>> paddle.utils.run_check()
Running verify PaddlePaddle program ... 
PaddlePaddle works well on 1 CPU.
W1102 17:33:39.837543  4740 fuse_all_reduce_op_pass.cc:76] Find all_reduce operators: 2. To make the speed faster, some all_reduce ops are fused during training, after fusion, the number of all_reduce ops is 2.
PaddlePaddle works well on 2 CPUs.
PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now.
>>> 

2.4, Paddle Detection installation

        Installation document reference: https://toscode.gitee.com/paddlepaddle/PaddleDetection/blob/release/2.5/docs/tutorials/INSTALL_cn.md
        Create a working directory and switch to the working directory to download the source code:

# mkdir -p /home/tools/baidu/paddle
# cd /home/tools/baidu/paddle
# git clone https://github.com/PaddlePaddle/PaddleDetection

        Install the PaddleDetection dependency library:

# cd /home/tools/baidu/paddle/PaddleDetection
# pip install -r requirements.txt

        Compile and install PaddleDetection:

# python setup.py install

        Verify installation:

# python ppdet/modeling/tests/test_architectures.py
.......
----------------------------------------------------------------------
Ran 7 tests in 5.532s

OK

        See the above output prompt, indicating that the installation is successful.

 2.5. Solve related dependency problems

        At this point, the paddle model export environment is basically built, but the problem of package dependency needs to be solved.

        Install the pip dependency viewing tool:

# pip install pipdeptree

        View dependencies:

# pipdeptree -p paddlepaddle
Warning!!! Possibly conflicting dependencies found:
* paddlepaddle==2.3.2
 - paddle-bfloat [required: ==0.1.7, installed: ?]
------------------------------------------------------------------------
paddlepaddle==2.3.2
  - astor [required: Any, installed: 0.8.1]
  - decorator [required: Any, installed: 5.1.1]
  - numpy [required: >=1.13, installed: 1.23.3]
  - opt-einsum [required: ==3.3.0, installed: 3.3.0]
    - numpy [required: >=1.7, installed: 1.23.3]
  - paddle-bfloat [required: ==0.1.7, installed: ?]
  - Pillow [required: Any, installed: 9.2.0]
  - protobuf [required: >=3.1.0,<=3.20.0, installed: 3.19.1]
  - requests [required: >=2.20.0, installed: 2.28.1]
    - certifi [required: >=2017.4.17, installed: 2022.9.24]
    - charset-normalizer [required: >=2,<3, installed: 2.0.4]
    - idna [required: >=2.5,<4, installed: 3.4]
    - urllib3 [required: >=1.21.1,<1.27, installed: 1.26.12]
  - six [required: Any, installed: 1.16.0]

        From the above printed information, we know some dependency package problems and fix them:

# pip install paddle-bfloat==0.1.7

3. Paddle to onnx to rknn environment

        The two environments of paddle to onnx and onnx to rknn can be built separately or together. Here we choose to build together to facilitate the alignment of onnx versions and avoid failures caused by incompatible onnx versions during the conversion process.

3.1. Create environment

        Select the python3.8.13 package to create the environment

# conda create --name paddle2rknn libprotobuf python==3.8.13

3.2, enter the environment

        The command is as follows:

# conda activate paddle2rknn

        Note: Unless otherwise specified, all operations below in this chapter are performed in the created environment.

3.3, RKNN-Toolkit2 tool installation

        RKNN-Toolkit2 is a development kit that provides users with model conversion, inference and performance evaluation on PC and Rockchip NPU platforms. RKNN-Toolkit2 is suitable for RK3566, RK3568, RK3588/RK3588S, RV1103, RV1106 and other types of chips. The open source address of RKNN-Toolkit2 is https://github.com/rockchip-linux/rknn-toolkit2, from which we can get its Baidu network disk download address.
        Baidu network disk address: https://eyun.baidu.com/s/3eTDMk6Y#sharelink/path=%2F
        Password:
        The API and driver version of rknpu on the RK3588 development board obtained by rknn is 1.3.0, so here Select the release version of RK_NPU_SDK_1.3.0 to download. After downloading and decompressing, the root directory of RKNN-Toolkit2 is /home/tools/rockchip/RK_NPU_SDK_1.3.0/rknn-toolkit2-1.3.0. Currently, there are two ways to install RKNN-Toolkit2: one is to install through the Python package installation and management tool pip; the other is to run the docker image with the complete RKNN-Toolkit2 toolkit. This paper adopts the first method.
        Switch to the root directory of RKNN-Toolkit2:

# cd /home/tools/rockchip/RK_NPU_SDK_1.3.0/rknn-toolkit2-1.3.0

        Install dependencies, because the python version of our environment is 3.8.13, so execute here:

# pip3 install -r doc/requirements_cp38-1.3.0.txt

        Install RKNN-Toolkit2:

# pip3 install packages/rknn_toolkit2-1.3.0_11912b58-cp38-cp38-linux_x86_64.whl

3.3, paddle2onnx tool installation

        paddle2onnx supports converting PaddlePaddle model format to ONNX model format. paddle2onnx also depends on the paddle package. In the new environment, the paddle package needs to be reinstalled. For the installation of the paddle package, please refer to the previous chapter.

        View paddle2onnx installable version:

# pip3 index versions paddle2onnx
WARNING: pip index is currently an experimental command. It may be removed/changed in a future release without prior warning.
paddle2onnx (1.0.1)
Available versions: 1.0.1, 1.0.0, 0.9.8, 0.9.7, 0.9.6, 0.9.5, 0.9.4, 0.9.2, 0.9.1, 0.9.0, 0.8.2, 0.8.1, 0.8, 0.7, 0.6, 0.5.1, 0.5, 0.4, 0.3.2, 0.3.1

        The latest version is installed by default, specify version 0.9.8 here, otherwise it will be incompatible with RKNN-Toolkit2 because the onnx version is too high:

# pip install paddle2onnx==0.9.8

3.4. Solve related dependency problems

        So far, the paddle to onnx to rknn environment has basically been built, but the problem of package dependency needs to be solved.

        Install the pip dependency viewing tool:

# pip install pipdeptree

        View dependencies:

# pipdeptree -p paddle2onnx
Warning!!! Possibly conflicting dependencies found:
* paddlepaddle==2.3.2
 - paddle-bfloat [required: ==0.1.7, installed: ?]
* rknn-toolkit2==1.3.0-11912b58
 - numpy [required: ==1.17.3, installed: 1.23.3]
 - protobuf [required: ==3.12.0, installed: 3.19.1]
 - requests [required: ==2.21.0, installed: 2.28.1]
------------------------------------------------------------------------
paddle2onnx==0.9.8

        From the information printed above, it is known that some dependent package versions are incorrect, so fix them:

# pip install paddle-bfloat==0.1.7
# pip install numpy==1.17.3
# pip install protobuf==3.12.0
# pip install requests==2.21.0

2. Model conversion

        Paddle currently has four types of models: target detection, classification, OCR, and segmentation. The ppyoloe selected here is a type of target detection.

1. Model export

        Reference documents:

        https://gitee.com/paddlepaddle/PaddleDetection/tree/develop
        https://gitee.com/paddlepaddle/PaddleDetection/blob/develop/deploy/EXPORT_MODEL.md

        Switch to the previously built model export environment and enter the PaddleDetection working directory:

# conda activate paddleExport
# cd /home/tools/baidu/paddle/PaddleDetection

        Model export You can download the model online for export:

# python tools/export_model.py \
    -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \
    --output_dir=/home/tools/baidu/paddle/model/ppyoloe \
    -o weights=https://paddledet.bj.bcebos.com/models/ppyoloe_crn_s_300e_coco.pdparams \
    use_gpu=False exclude_nms=True

        You can also download the original model file locally for export:

# python tools/export_model.py \
    -c configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \
    --output_dir=/home/tools/baidu/paddle/model/ppyoloe \
    -o weights=/home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco.pdparams \
    use_gpu=False exclude_nms=True

Parameter Description:

-c specifies the configuration file

--output_dir model save path

-o Output related configuration, where:

                          weights: the trained model, the extension is pdparams

                          use_gpu: whether to use gpu

                          exclude_nms: cut out the nms part of the post-processing in the model

There is no gpu in the current environment, so set use_gpu=False;

rknn currently does not support the NonZero operator, so to cut out the nms part of the post-processing in the model, set exclude_nms=True

The prediction model will be exported to the /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco directory, respectively infer_cfg.yml, model.pdiparams, model.pdiparams.info, model.pdmodel.

2. paddle to onnx

        Reference: https://toscode.gitee.com/paddlepaddle/Paddle2ONNX

        Switch to paddle to onnx to rknn environment:

# conda activate paddle2rknn

        paddle to onnx command:

# paddle2onnx --model_dir /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/ \
    --model_filename model.pdmodel  \
    --params_filename model.pdiparams \
    --opset_version 12 \
    --save_file /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx \
    --enable_onnx_checker True

Parameter Description:

--model_dir: Configure the directory path containing the Paddle model

--model_filename: Configure  --model_dir the file name of the storage network structure under

--params_filename: Configure  --model_dir the name of the file under which model parameters are stored

--opset_version: The configuration is converted to the OpSet version of ONNX. Currently, it supports multiple versions such as 7~16. The default is 9, and 12 is selected here to be compatible with rknn-toolkit2.

--save_file: Specify the converted model save directory path

--enable_onnx_checker: Configure whether to check the correctness of the exported ONNX model, it is recommended to turn on this switch, the default is False

        The converted onnx file is located at: /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx, but this model cannot be converted into rknn, because rknn needs a fixed input shape, so we are converting Sometimes you also need to use input_shape_dict to set the fixed input shape. So how to determine the parameters of the input shape? From: https://toscode.gitee.com/paddlepaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md

 We can know that the paddle target detection model has 1~3 inputs, so how to determine what value to fill in? We can use the following python code to first print out the input and output of the previously transferred onnx model:

import onnx
import numpy as np
import logging
logging.basicConfig(level=logging.INFO)

def onnx_datatype_to_npType(data_type):
    if data_type == 1:
        return np.float32
    else:
        raise TypeError("don't support data type")


def parser_initializer(initializer):
    name = initializer.name
    logging.info(f"initializer name: {name}")

    dims = initializer.dims
    shape = [x for x in dims]
    logging.info(f"initializer with shape:{shape}")

    dtype = initializer.data_type
    logging.info(f"initializer with type: {onnx_datatype_to_npType(dtype)} ")
    
    # print tenth buffer
    weights = np.frombuffer(initializer.raw_data, dtype=onnx_datatype_to_npType(dtype))
    logging.info(f"initializer first 10 wights:{weights[:10]}")



def parser_tensor(tensor, use='normal'):
    name = tensor.name
    logging.info(f"{use} tensor name: {name}")

    data_type = tensor.type.tensor_type.elem_type
    logging.info(f"{use} tensor data type: {data_type}")

    dims = tensor.type.tensor_type.shape.dim
    shape = []
    for i, dim in enumerate(dims):
        shape.append(dim.dim_value)
    logging.info(f"{use} tensor with shape:{shape} ")


def parser_node(node):
    def attri_value(attri):
        if attri.type == 1:
            return attri.i
        elif attri.type == 7:
            return list(attri.ints)
        
    name = node.name
    logging.info(f"node name:{name}")

    opType = node.op_type
    logging.info(f"node op type:{opType}")

    inputs = list(node.input)
    logging.info(f"node with {len(inputs)} inputs:{inputs}")

    outputs = list(node.output)
    logging.info(f"node with {len(outputs)} outputs:{outputs}")
    
    attributes = node.attribute
    for attri in attributes:
        name = attri.name
        value = attri_value(attri)
        logging.info(f"{name} with value:{value}")


def parser_info(onnx_model):
    ir_version = onnx_model.ir_version
    producer_name = onnx_model.producer_name
    producer_version = onnx_model.producer_version
    for info in [ir_version, producer_name, producer_version]:
        logging.info("onnx model with info:{}".format(info))

def parser_inputs(onnx_graph):
    inputs = onnx_graph.input
    for input in inputs:
        parser_tensor(input, 'input')

def parser_outputs(onnx_graph):
    outputs = onnx_graph.output
    for output in outputs:
        parser_tensor(output, 'output')

def parser_graph_initializers(onnx_graph):
    initializers = onnx_graph.initializer
    for initializer in initializers:
        parser_initializer(initializer)


def parser_graph_nodes(onnx_graph):
    nodes = onnx_graph.node
    for node in nodes:
        parser_node(node)
        t = 1

def onnx_parser():
    model_path = '/home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx'
    
    model = onnx.load(model_path)

    # 0.
    parser_info(model)

    graph = model.graph

    # 1.
    parser_inputs(graph)

    # 2. 
    parser_outputs(graph)

    # 3.
    #parser_graph_initializers(graph)

    # 4. 
    #parser_graph_nodes(graph)


if __name__ == '__main__':
    onnx_parser()

The code is saved as printOnnx.py, and then executed:

# python printOnnx.py 
INFO:root:onnx model with info:7
INFO:root:onnx model with info:PaddlePaddle
INFO:root:onnx model with info:
INFO:root:input tensor name: image
INFO:root:input tensor data type: 1
INFO:root:input tensor with shape:[-1, 3, 640, 640] 
INFO:root:input tensor name: scale_factor
INFO:root:input tensor data type: 1
INFO:root:input tensor with shape:[-1, 2] 
INFO:root:output tensor name: tmp_17
INFO:root:output tensor data type: 1
INFO:root:output tensor with shape:[-1, 8400, 4] 
INFO:root:output tensor name: concat_14.tmp_0
INFO:root:output tensor data type: 1
INFO:root:output tensor with shape:[-1, 80, 8400]

From the printed information, we can see that ppyoloe has two input shapes, where the batch is -1, which means it is uncertain, and other parameters such as image size can be learned from it. Export an onnx model with a fixed input shape using the following new command:

# paddle2onnx --model_dir /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/ \
    --model_filename model.pdmodel  \
    --params_filename model.pdiparams \
    --opset_version 12 \
    --save_file /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx \
    --input_shape_dict="{'image':[1,3,640,640], 'scale_factor':[1,2]}" \
    --enable_onnx_checker True

If it is a higher version of paddle2onnx (looks like > 0.9.8), you need to use the following command:

# paddle2onnx --model_dir /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/ \
    --model_filename model.pdmodel  \
    --params_filename model.pdiparams \
    --opset_version 12 \
    --save_file /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx \
    --enable_onnx_checker True

# python -m paddle2onnx.optimize \
    --input_model /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx \
    --output_model /home/tools/baidu/paddle/model/ppyoloe/ppyoloe_crn_s_300e_coco/model.onnx \
    --input_shape_dict "{'image':[1,3,640,640], 'scale_factor':[1,2]}"

After the conversion, you can see that the input and output shapes are fixed:

# python printOnnx.py 
INFO:root:onnx model with info:7
INFO:root:onnx model with info:PaddlePaddle
INFO:root:onnx model with info:
INFO:root:input tensor name: image
INFO:root:input tensor data type: 1
INFO:root:input tensor with shape:[1, 3, 640, 640] 
INFO:root:input tensor name: scale_factor
INFO:root:input tensor data type: 1
INFO:root:input tensor with shape:[1, 2] 
INFO:root:output tensor name: tmp_17
INFO:root:output tensor data type: 1
INFO:root:output tensor with shape:[1, 8400, 4] 
INFO:root:output tensor name: concat_14.tmp_0
INFO:root:output tensor data type: 1
INFO:root:output tensor with shape:[1, 80, 8400] 

3. Onnx to rknn

        Download RKNN-Toolkit2 and there is rknpu2_1.3.0.tar.gz file in it. After decompression, refer to RK_NPU_SDK_1.3.0/rknpu2_1.3.0/examples/rknn_yolov5_demo/convert_rknn_demo/yolov5/onnx2rknn.py to write the code of ppyoloe's onnx to rknn:

# coding=gbk
import cv2
import numpy as np

from rknn.api import RKNN
import os

ONNX_MODEL = 'ppyoloe_crn_s_300e_coco/model.onnx'
RKNN_MODEL = 'ppyoloe_crn_s_300e_coco/model.rknn'

if __name__ == '__main__':
    NEED_BUILD_MODEL = True
    # NEED_BUILD_MODEL = False
    
    #生成scale_factor.npy
    arr = np.array([1.0, 1.0])
    np.save("scale_factor.npy", arr)
    
    # Create RKNN object
    rknn = RKNN(verbose=True)
    if NEED_BUILD_MODEL:
        DATASET = './dataset.txt'
        #mean_values和std_values查看相应的infer_cfg.yml文件
        #注意:infer_cfg.yml下is_scale:值为true,所以values值要除以scale[1.0/255],即:将values*255得到的值填入下面代码 
        #rknn默认读图方式是RGB,如果这里训练时是使用BGR,则量化时需要RGB转BGR
        #rknn.config(mean_values=[[123.675, 116.28, 103.53]], std_values=[[58.395, 57.12, 57.375]], target_platform="rk3588")
        rknn.config(mean_values=[[123.675, 116.28, 103.53]], std_values=[[58.395, 57.12, 57.375]], target_platform="rk3588", quant_img_RGB2BGR=True)
        # Load model
        print('--> Loading model')
        #ret = rknn.load_onnx(model=ONNX_MODEL)
        ret = rknn.load_onnx(model=ONNX_MODEL, input_size_list=[[1,3,640,640],[1,2]])
        if ret != 0:
            print('load model failed!')
            exit(ret)
        print('done')

        # Build model
        print('--> Building model')
        ret = rknn.build(do_quantization=True, dataset=DATASET)                 #量化
        #ret = rknn.build(do_quantization=False, dataset=DATASET)                 #不量化
        if ret != 0:
            print('build model failed.')
            exit(ret)
        print('done')

        # Export rknn model
        print('--> Export RKNN model: {}'.format(RKNN_MODEL))
        ret = rknn.export_rknn(RKNN_MODEL)
        if ret != 0:
            print('Export rknn model failed.')
            exit(ret)
        print('done')
        
    else:
        ret = rknn.load_rknn(RKNN_MODEL)

    rknn.release()

Here are a few places to pay attention to when quantifying:

(1) The default image reading method of rknn is RGB. If BGR is used for training here, RGB needs to be converted to BGR for quantization. Quant_img_RGB2BGR=True needs to be configured in rknn.config. What format does ppyoloe use for training? Haven't verified here yet.

(2) When transferring from paddle to onnx, we learned that ppyoloe has two input shapes, so when preparing the quantization correction data set, we also need to provide two input shape data, that is, dataset.txt has two files per line , separated by spaces:

# cat dataset.txt 
bus.jpg scale_factor.npy
1.jpg scale_factor.npy

The first file is an image file

The second file is the shape information whose input name is scale_factor, in npy format, indicating that the size of the input image is larger than the size of the real image, which is set to 1.0 here, and the file is directly generated in the above code.

        Run the above code to realize onnx to rknn:

# python3 onnx2rknn.py

        Possible errors:

E build: Catch exception when building RKNN model!
E build: Traceback (most recent call last):
E build:   File "rknn/api/rknn_base.py", line 1680, in rknn.api.rknn_base.RKNNBase.build
E build:   File "rknn/api/rknn_base.py", line 363, in rknn.api.rknn_base.RKNNBase._generate_rknn
E build:   File "rknn/api/rknn_base.py", line 270, in rknn.api.rknn_base.RKNNBase._build_rknn
E build: ImportError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /root/anaconda3/envs/paddle2rknn/lib/python3.8/site-packages/rknn/api/lib/linux-x86_64/cp38/librknnc_v2.so)
build model failed.

The reason is that version 2.29 of GLIBC is required. For the solution, refer to: https://www.cnblogs.com/chenyirong/p/16342370.html

Then re-convert, if there is no accident, the rknn model file we want will be generated under the path set by the code, deploy it to the development board and you can play happily~

3. Run the routine

        I don't have a development board at present, I will add it when I have one!

Guess you like

Origin blog.csdn.net/buyishengun/article/details/127653529