rockchip-linux / rknn-toolkit

BSD 3-Clause "New" or "Revised" License
829 stars 175 forks source link

Yolov8 conversion on Ubuntu 22.04 host machine for RK3399PRO Board #426

Open trohit920 opened 10 months ago

trohit920 commented 10 months ago

I and ollowing this repo to install RKNN-Toolkit on host PC to convert YOLO-V8 Model to RKNN format and deploy on RK3399PRO board. However, I encountered below error while doing so,

WARNING - 'configs' in yaml file is deprecate, rename it as 'config'
W rknn-toolkit version: 1.7.5
WARNING - rknn.api import failed, skip rknn_config_check
========== parser_config ==========
TOOLKIT_MAIN_VERSION: 1
RK_device_platform: RK3399PRO
model_framework: pytorch
verbose: False
quantize: True
dataset: ../../../../../datasets/COCO/coco_subset_10.txt
graph:
  in_0:
    shape: 1,3,640,640
    mean_values: 0
    std_values: 255
    img_type: RGB
config:
  quantized_dtype: asymmetric_affine-u8
  target_platform: RK3399PRO
  quantized_algorithm: normal
  optimization_level: 3
  mean_values: [[0, 0, 0]]
  std_values: [[255, 255, 255]]
  reorder_channel: 0 1 2
pre_compile: online
core_mask: 1
export_rknn:
  export_path: ./model_cvt/RK1808_3399pro/yolov8n_rknnopt_RK1808_3399pro_u8.rknn
model_file_path: yolov8n_rknnopt.torchscript
build:
  do_quantization: True
  dataset: ./../../../../../datasets/COCO/coco_subset_10.txt
qnnpack: False
load:
  model: ./yolov8n_rknnopt.torchscript
  input_size_list: [[3, 640, 640]]
inputs:
  in_0:
    shape: [1, 3, 640, 640]
    mean_values: [0, 0, 0]
    std_values: [255, 255, 255]
    img_type: RGB
outputs:
input_example: [{'in_0': '../../../../../datasets/COCO/val_test/000000000285.jpg'}, {'in_0': '../../  ...
export_pre_compile_path: ./model_cvt/RK1808_3399pro/yolov8n_rknnopt_RK1808_3399pro_u8_precompile.rknn
===================================
---> Create RKNN object
W rknn-toolkit version: 1.7.5
---> Seting RKNN config
---> Loading pytorch model
Traceback (most recent call last):
  File "../../../../../common/rknn_converter/rknn_convert.py", line 99, in <module>
    convert(config_dict, args)
  File "../../../../../common/rknn_converter/rknn_convert.py", line 19, in convert
    rknn = cp.convert()
  File "/home/fazliddin/rock_chip/rknn_model_zoo/common/rknn_converter/phase.py", line 122, in convert
    load_function(**model_config_dict['load'])
  File "/home/fazliddin/.conda/envs/rk3399pro/lib/python3.8/site-packages/rknn/api/rknn.py", line 227, in load_pytorch
    ret = self.rknn_base.load_pytorch(model, input_size_list, inputs, outputs, convert_engine)
  File "rknn/api/rknn_base.py", line 439, in rknn.api.rknn_base.RKNNBase.load_pytorch
  File "/home/fazliddin/.conda/envs/rk3399pro/lib/python3.8/site-packages/rknn/base/acuitylib/__init__.py", line 1, in <module>
    from acuitylib.optimize.optimizer import Optimizer
  File "rknn/base/acuitylib/optimize/optimizer.py", line 9, in init rknn.base.acuitylib.optimize.optimizer
  File "/home/fazliddin/.conda/envs/rk3399pro/lib/python3.8/site-packages/rknn/base/acuitylib/__init__.py", line 1, in <module>
    from acuitylib.optimize.optimizer import Optimizer
ImportError: cannot import name 'Optimizer' from partially initialized module 'acuitylib.optimize.optimizer' (most likely due to a circular import) (/home/fazliddin/.conda/envs/rk3399pro/lib/python3.8/site-packages/rknn/base/acuitylib/optimize/optimizer.cpython-38-x86_64-linux-gnu.so)
eRaul commented 10 months ago

First confirm whether the examples/pytorch/resnet18 example can run normally.

trohit920 commented 10 months ago

I can successfully convert the YOLOV8 Onnx model to RKNN Format using the toolkit on host PC. However while running inference board it gives me below error with both Resnet model and my own model.

ubuntu@jammy:~/packages/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite$ python test.py 
--> Load RKNN model
done
--> Init runtime environment
E Catch exception when init runtime!
E Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.7/site-packages/rknnlite/api/rknn_lite.py", line 144, in init_runtime
    async_mode=async_mode, rknn2precompile=rknn2precompile)
  File "rknnlite/api/rknn_runtime.py", line 282, in rknnlite.api.rknn_runtime.RKNNRuntime.__init__
  File "rknnlite/api/rknn_runtime.py", line 361, in rknnlite.api.rknn_runtime.RKNNRuntime._get_target_soc
Exception: Please specify the target in init_runtime!

Init runtime environment failed

Here is the output of model converted on host PC using the toolkit:

D Packing Conv_Conv_31_155 ...
D Packing Conv_Conv_35_165 ...
D Packing Conv_Conv_38_145 ...
D Packing Conv_Conv_3_233 ...
D Packing Conv_Conv_43_120 ...
D Packing Conv_Conv_46_227 ...
D Packing Conv_Conv_49_223 ...
D Packing Conv_Conv_53_215 ...
D Packing Conv_Conv_56_200 ...
D Packing Conv_Conv_60_217 ...
D Packing Conv_Conv_63_202 ...
D Packing Conv_Conv_68_180 ...
D Packing Conv_Conv_6_231 ...
D Packing Conv_Conv_71_219 ...
D Packing Conv_Conv_74_204 ...
D Packing Conv_Conv_78_189 ...
D Packing Conv_Conv_81_182 ...
D Packing Conv_Conv_86_154 ...
D Packing Conv_Conv_89_150 ...
D Packing Conv_Conv_96_126 ...
D Packing Initializer_438_9 ...
D Disable rknn op statistic.
D output tensor id = 0, name = Concat_Concat_235/out0_0
D input tensor id = 1, name = images_238
I Build config finished.

(rk3399pro) fazliddin@fazliddin-AORUS-17G-WB:~/rock_chip/rknn-toolkit-v1.7.5-packages/packages$ python -m rknn.bin.list_devices 
W rknn-toolkit version: 1.7.5
*************************
all device(s) with adb mode:
cdec2dfbaf6a4679
*************************
trohit920 commented 10 months ago

@eRaul here is the output of proxy command:

ubuntu@jammy:~/packages/RK3399Pro_npu/drivers/npu_transfer_proxy/linux-aarch64$ ./npu_transfer_proxy 
I NPUTransfer: Starting NPU Transfer Proxy, Transfer version 2.1.0 (b5861e7@2020-11-23T11:50:51), devid = 0123456789ABCDEF, pid = 1358:790
eRaul commented 10 months ago

If you are running the inference script on the PC, you need to specify target='rk3399pro' where you call the init_runtime. interface.