Resnet34 conversion

Hi,

I am using Rk3566 for inference, as far as resnet34 is concerned there is no any test.py given for conversion of .onnx to .rknn . I have resnet34.onnx and I want to convert it to resnet34.rknn how can i do it?

Hi, @Shubham_Mali

If you want to convert ResNet34 onnx to rknn, you can reuse the ResNet code in rknn_model_zoo,

The next thing you need to do is config the code a little bit

  • install the rknn-toolkit2 and rknn-mocel-zoo follow the radxa docs

  • config your ResNet34 path in DEFAULT_RKNN_PATH and DEFAULT_ONNX_PATH

  • if you use your own dataset to train the model, you can set the mean and std in rknn.config, or keep the same value

  • comment the part of inference code( after rknn.export_rknn) if you just want to convert the model and do not want to use simulator inference on your PC

after that you can run this python script in command line to get rknn model:

python3 resnet.py resnet34_onnx_model_path rk3566 

More detail of rknn convert information you can visit rknn-toolkit2 usage

best,

hii @Morgan,

Thanks for the valuable suggestion,

The method given by you has worked for me and now I can get the .rknn model for ResNet34. Now i am running my inference script on RK3566 platform (using RknnLite( )).

While running inference I am getting following version error:

I RKNN: [07:20:01.001] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)
I RKNN: [07:20:02.003] RKNN Driver Information: version: 0.4.2
E RKNN: [07:20:02.007] 6, 4
E RKNN: [07:20:02.007] Invalid RKNN model version 6
E RKNN: [07:20:02.007] rknn_init, load model failed!
E Catch exception when init runtime!
E Traceback (most recent call last):
File “/home/rock/.local/lib/python3.9/site-packages/rknnlite/api/rknn_lite.py”, line 148, in init_runtime
self.rknn_runtime.build_graph(self.rknn_data, self.load_model_in_npu)
File “rknnlite/api/rknn_runtime.py”, line 875, in rknnlite.api.rknn_runtime.RKNNRuntime.build_graph
Exception: RKNN init failed. error code: RKNN_ERR_MODEL_INVALID

— Running on NPU core = -1 —
Init runtime environment failed

I have setup of RknnLite on board and I want to go with same version. Can we do something in model conversion to match the version of RknnLite and converted .rknn model?

hi @Shubham_Mali

i think it is version dismatch between rknn-toolkit2 and rknn-toolkit2-lite, Are you install the rknn-toolkit2-lite in same version with rknn SDK_v1.X?

for example the docs in Radxa is use rknn_SDK v1.6 which i recommend

you can check on PC rknn env by

$ pip3 list | grep rknn
rknn-toolkit2                1.6.0+81f21f4d

and check tknn-toolkit-lite your board

rock@rock-5a:~$ pip3 list | grep rknn
rknnlite          1.6.0

please make sure both in same version

best

hii @Morgan,
my rknn-toolkit-lite2 is 1.5.0
and
my rknn-toolkit2 is 1.6.0+81f21f4d

is it poosible to upgrade the rknn-toolkit-lite2 using pip3 command? or anything else we have to do?

Hi @Shubham_Mali

yeah, they are dismatch, you could upload the rknn-toolkit2-lite on board,

first, uninstall the old version by

pip3 uninstall rknn-toolkit-lite2

then download the v1.6.0 rknn-toolkit-lite-2 wheel package from here, make sure use the same version of the python3 on board

for example if you use python3.9

pip3 install https://github.com/rockchip-linux/rknn-toolkit2/blob/v1.6.0/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.6.0-cp39-cp39-linux_aarch64.whl

after all done, you can use NPU to inference and enjoy

best

hii @Morgan,

if i uninstall rknn-lite 1.5.0, my current codes with the other models are going to run as it is? or i have to make other changes?

hi @Shubham_Mali

You could use the virtualenv module to create a indivision clean python env to install the rknn-lite-v1.6.0 in the folder which you need to inference with this version, so you can keep them both,

pip3 install virtualenv
# in the resnet34 folder 
python3 -m virtualenv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install https://github.com/rockchip-linux/rknn-toolkit2/blob/v1.6.0/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.6.0-cp39-cp39-linux_aarch64.whl
# pip3 install xxxxxx some pakeage you need 

best

hii @Morgan,

Tried with the commands you have given still i am getting

I RKNN: [07:20:01.001] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)
I RKNN: [07:20:02.003] RKNN Driver Information: version: 0.4.2
E RKNN: [07:20:02.007] 6, 4
E RKNN: [07:20:02.007] Invalid RKNN model version 6
E RKNN: [07:20:02.007] rknn_init, load model failed!
E Catch exception when init runtime!
E Traceback (most recent call last):
File “/home/rock/.local/lib/python3.9/site-packages/rknnlite/api/rknn_lite.py”, line 148, in init_runtime
self.rknn_runtime.build_graph(self.rknn_data, self.load_model_in_npu)
File “rknnlite/api/rknn_runtime.py”, line 875, in rknnlite.api.rknn_runtime.RKNNRuntime.build_graph
Exception: RKNN init failed. error code: RKNN_ERR_MODEL_INVALID

— Running on NPU core = -1 —
Init runtime environment failed

hii @Morgan

also i am getting following error

I RKNN: [10:19:34.962] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)
I RKNN: [10:19:34.963] RKNN Driver Information: version: 0.4.2
I RKNN: [10:19:34.963] RKNN Model Information: version: 4, toolkit version: 1.5.0+1fa95b5c(compiler version: 1.5.0 (e6fe0c678@2023-05-25T08:11:09)), target: RKNPU lite, target platform: rk3566, framework name: PyTorch, framework layout: NCHW, model inference type: static_shape
Traceback (most recent call last):
File “/home/rock/rknn_venv/rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite/test_try_webcam_classification.py”, line 74, in
ret = rknn_lite.init_runtime()
File “/home/rock/rknn_venv/lib/python3.9/site-packages/rknnlite/api/rknn_lite.py”, line 177, in init_runtime
self.rknn_runtime.extend_rt_lib()
File “rknnlite/api/rknn_runtime.py”, line 1290, in rknnlite.api.rknn_runtime.RKNNRuntime.extend_rt_lib
File “/usr/lib/python3.9/ctypes/init.py”, line 387, in getattr
func = self.getitem(name)
File “/usr/lib/python3.9/ctypes/init.py”, line 392, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /usr/lib/librknnrt.so: undefined symbol: rknn_set_input_shapes

Hi @Shubham_Mali

yeah, you still dismatch with the rknn-toolkit2 and rknn-toolkit2-lite, as you see the error info. it mention your board librknnrt is 1.5.0 and toolkit version is 1.5.0, but your PC covertor tools is v1.6.0, if you comfire your board are in virtualenv with v1.6.0 rknn-toolkit2-lite and your model was converted by v1.6.0 rknn-toolkit2 it shoul be work

best