Toybrick EN

中文 / EN
Toybrick EN Wiki TB-96AI Model Conversion
Model Conversion

Rockchip offers the RKNN-Toolkit development kit for model conversion, forward inference, and performance evaluation.

Users can easily perform the following functions through the provided python interface:

1) Model conversion: support CaffeTensorflowTensorFlow LiteONNXDarknet model, support RKNN model import and export, and so the models can be loaded and used on the hardware platform.

2) forward inference: user can simulate running the model on the PC and get the inference results, and run the model on the specified hardware platform RK3399Pro (or RK3399Pro Linux) and get the inference results.

3) performance evaluation: user can simulate running the model on a PC to get both the total time spent on the model and the time-consuming information of each layer. User can also run the model on the specified hardware platform RK3399Pro (or RK3399Pro Linux) by online debugging, and get both the total time of the model running on the hardware and the time-consuming information of each layer.

This chapter mainly explains how to perform model conversion on the TB-96AI RK3399Pro development board. For other function descriptions, please refer to the RKNN-Toolkit User Guide: "RKNN-Toolkit User Guide_V*.pdf".


Installation preparation

  1. sudo dnf install -y cmake gcc gcc-c++ protobuf-devel protobuf-compiler lapack-devel
    sudo dnf install -y python3-devel python3-opencv python3-numpy-f2py python3-h5py python3-lmdb  python3-grpcio
    pip3 install scipy-1.2.0-cp36-cp36m-linux_aarch64.whl
    pip3 install onnx-1.4.1-cp36-cp36m-linux_aarch64.whl
    pip3 install tensorflow-1.10.1-cp36-cp36m-linux_aarch64.whl

After installing the above basic package, install the rknn-toolkit wheel package.
RKNN wheel package and other Python wheel packages can be downloaded from
OneDrive
Since pip does not have a ready-made aarch64 version of the scipy and onnx wheel packages, we have provided a compiled wheel package.
If you want the latest version of the wheel package or find a problem with the pre-compiled wheel package, you can use pip to install it yourself. This will compile and install the wheel package. It will take a long time and you need to wait patiently.

  1. pip3 install scipy
    pip3 install onnx

If the installation encounters an error, please install the corresponding software package according to the error message. 


API call flow

1551087188370663.png

 

Example

  1. from rknn.api import RKNN

    INPUT_SIZE = 64

    if __name__ == '__main__':
     # Create an RKNN execution object
        rknn = RKNN()
    # Configure model input for NPU preprocessing of input data
    # channel_mean_value='0 0 0 255', when runing forward inference, the RGB data will be converted as follows
    # (R - 0)/255, (G - 0)/255, (B - 0)/255, The RKNN model automatically performs the mean and normalization
    # reorder_channel=' 0 1 2' , used to specify whether to adjust the image channel order, set to 0 1 2, means no adjustment according to the input image channel order.
    # reorder_channel=' 2 1 0' , indicates that 0 and 2 channels are exchanged. If the input is RGB, it will be adjusted to BGR. If it is BGR will be adjusted to RGB
    #Image channel order is not adjusted
        rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')

    # load TensorFlow model
    # tf_pb='digital_gesture.pb' specify the TensorFlow model to be converted
    # inputs specify the input node in the model
    # outputs specify the output node in the model
    # input_size_list specify the size of the model input
        print('--> Loading model')
        rknn.load_tensorflow(tf_pb='digital_gesture.pb',
                             inputs=['input_x'],
                             outputs=['probability'],
                             input_size_list=[[INPUT_SIZE, INPUT_SIZE, 3]])
        print('done')

    # Create a parsing pb model
    # do_quantization=False do not to be quantified
    # Quantization will reduce the size of the model and increase the speed of the operation, but there will be loss of precision.
        print('--> Building model')
        rknn.build(do_quantization=False)
        print('done')

    # Export and save rknn model file
        rknn.export_rknn('./digital_gesture.rknn')

        # Release RKNN Context
        rknn.release()

 

Products Store Community Wiki Download About TB


To Top