Page 1 of 1

Issues Converting ONNX MOdel to RKNN on Luckfox Pico Ultra W

Posted: 2025-02-24 6:32
by taiibt
Hi everyone,
I'm currently working on a project using the Luckfox Pico Ultra W with Buildroot. I'm trying to convert an ONNX model to RKNN using the RKNN-Toolkit2, but I've encountered issues during the conversion process.

Model information:
The model I'm using is the Yolov5 fire detection model, which can be found at: https://github.com/spacewalk01/yolov5-f ... main/model

I tried converting the ONNX model to RKNN using RKNN-Toolkit2 versions 1.6.0 and 2.3.0
I referred to the RKNN Inference Test guide on the Luckfox wiki and followed the steps there.
Previously, I was able to implement an object detection example using YOLOv5 from Rockchip following the RKNN Inference Test guide, and this model worked well.

Errors Encountered:

With RKNN-Toolkit2 version 1.6.0:

Code: Select all

(RKNN-Toolkit2) bt@bt:~/Test-Yolov5_fire/onnx_to_rknn/scripts/luckfox_onnx_to_rknn/convert$ python convert.py ../model/yolov5s_best.onnx ../dataset/50.txt ../model/yolov5s_best.rknn Yolov5 
W __init__: rknn-toolkit2 version: 1.6.0+81f21f4d 
--> Config model 
done 
--> Loading model 
W load_onnx: It is recommended onnx opset 19, but your onnx model opset is 12! 
W load_onnx: Model converted from pytorch, 'opset_version' should be set 19 in torch.onnx.export for successful convert! 
Loading : 100%|█████████████████████████████████████████████████| 135/135 [00:00<00:00, 6453.29it/s] 
done 
--> Building model 
W build: found outlier value, this may affect quantization accuracy 
const name          abs_mean    abs_std     outlier value 
onnx::Conv_371      0.95        1.68        17.561       
E build: Unsupport file 0! 
W build: ===================== WARN(4) ===================== 
E rknn-toolkit2 version: 1.6.0+81f21f4d 
E build: Catch exception when building RKNN model! 
E build: Traceback (most recent call last): 
E build:   File "rknn/api/rknn_base.py", line 1992, in rknn.api.rknn_base.RKNNBase.build 
E build:   File "rknn/api/graph_optimizer.py", line 1949, in rknn.api.graph_optimizer.GraphOptimizer.sparse_weight 
E build:   File "rknn/api/sparse_weight.py", line 528, in rknn.api.sparse_weight.sparse_weight 
E build:   File "rknn/api/sparse_weight.py", line 75, in rknn.api.sparse_weight._range_input 
E build:   File "rknn/api/rknn_log.py", line 92, in rknn.api.rknn_log.RKNNLog.e 
E build: ValueError: Unsupport file 0! 
W If you can't handle this error, please try updating to the latest version of the toolkit2 and runtime from: 
  https://console.zbox.filez.com/l/I00fc3 (Pwd: rknn)  Path: RKNPU2_SDK / 1.X.X / develop / 
  If the error still exists in the latest version, please collect the corresponding error logs and the model, 
  convert script, and input data that can reproduce the problem, and then submit an issue on: 
  https://redmine.rock-chips.com (Please consult our sales or FAE for the redmine account) 
Build model failed! 
With RKNN-Toolkit2 version 2.3.0:

Code: Select all

(RKNN-Toolkit2-2.3.0) bt@bt:~/Test-Yolov5_fire/onnx_to_rknn/scripts/luckfox_onnx_to_rknn/convert$ python convert.py ../model/yolov5s_best.onnx ../dataset/50.txt ../model/yolov5s_best.rknn Yolov5 
I rknn-toolkit2 version: 2.3.0 
--> Config model 
done 
--> Loading model 
I Loading : 100%|███████████████████████████████████████████████| 121/121 [00:00<00:00, 5865.48it/s] 
done 
--> Building model 
I OpFusing 0: 100%|███████████████████████████████████████████████| 100/100 [00:01<00:00, 90.17it/s] 
I OpFusing 1 : 100%|██████████████████████████████████████████████| 100/100 [00:01<00:00, 63.66it/s] 
I OpFusing 2 : 100%|██████████████████████████████████████████████| 100/100 [00:02<00:00, 36.36it/s] 
W build: found outlier value, this may affect quantization accuracy 
                     const name          abs_mean    abs_std     outlier value 
                        onnx::Conv_371      0.95        1.68        17.561       
E build: Unsupport file 0! 
W build: ===================== WARN(1) ===================== 
E rknn-toolkit2 version: 2.3.0 
E build: Traceback (most recent call last): 
  File "rknn/api/rknn_log.py", line 344, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper 
  File "rknn/api/rknn_base.py", line 1967, in rknn.api.rknn_base.RKNNBase.build 
  File "rknn/api/graph_optimizer.py", line 2340, in rknn.api.graph_optimizer.GraphOptimizer.sparse_weight 
  File "rknn/api/sparse_weight.py", line 542, in rknn.api.sparse_weight.sparse_weight 
  File "rknn/api/sparse_weight.py", line 83, in rknn.api.sparse_weight._range_input 
  File "rknn/api/rknn_log.py", line 95, in rknn.api.rknn_log.RKNNLog.e 
ValueError: Unsupport file 0! 
 
I ===================== WARN(0) ===================== 
E rknn-toolkit2 version: 2.3.0 
Traceback (most recent call last): 
  File "rknn/api/rknn_log.py", line 344, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper 
  File "rknn/api/rknn_base.py", line 1967, in rknn.api.rknn_base.RKNNBase.build 
  File "rknn/api/graph_optimizer.py", line 2340, in rknn.api.graph_optimizer.GraphOptimizer.sparse_weight 
  File "rknn/api/sparse_weight.py", line 542, in rknn.api.sparse_weight.sparse_weight 
  File "rknn/api/sparse_weight.py", line 83, in rknn.api.sparse_weight._range_input 
  File "rknn/api/rknn_log.py", line 95, in rknn.api.rknn_log.RKNNLog.e 
ValueError: Unsupport file 0! 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "convert.py", line 44, in <module> 
    ret = rknn.build(do_quantization=True, dataset=dataset_path) 
  File "/home/taibt/miniconda3/envs/RKNN-Toolkit2-2.3.0/lib/python3.8/site-packages/rknn/api/rknn.py", line 192, in build 
    return self.rknn_base.build(do_quantization=do_quantization, dataset=dataset, expand_batch_size=rknn_batch_size) 
  File "rknn/api/rknn_log.py", line 349, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper 
  File "rknn/api/rknn_log.py", line 95, in rknn.api.rknn_log.RKNNLog.e 
ValueError: Traceback (most recent call last): 
  File "rknn/api/rknn_log.py", line 344, in rknn.api.rknn_log.error_catch_decorator.error_catch_wrapper 
  File "rknn/api/rknn_base.py", line 1967, in rknn.api.rknn_base.RKNNBase.build 
  File "rknn/api/graph_optimizer.py", line 2340, in rknn.api.graph_optimizer.GraphOptimizer.sparse_weight 
  File "rknn/api/sparse_weight.py", line 542, in rknn.api.sparse_weight.sparse_weight 
  File "rknn/api/sparse_weight.py", line 83, in rknn.api.sparse_weight._range_input 
  File "rknn/api/rknn_log.py", line 95, in rknn.api.rknn_log.RKNNLog.e 
ValueError: Unsupport file 0! 
Even though I upgraded the toolkit, the error persists, and the model fails during the build phase.

Questions:
1. Has anyone encountered a similar issue with Luckfox Pico Ultra W or RKNN-Toolkit2 when converting ONNX models?
2. Are there any specific steps or configuration changes I can apply to resolve the "Unsupport file 0!" error?
3.Could the issue be related to the model itself (e.g., unsupported operators or opset issues), and how can it be resolved?

I would appreciate any advice or tips on how to move forward with this issue.

Thank you!

Re: Issues Converting ONNX MOdel to RKNN on Luckfox Pico Ultra W

Posted: 2025-02-24 12:19
by Crocodile
Hello, the NPU of RV1106 itself supports limited operators, the yolov5 routine mentioned in the wiki is based on the https://github.com/airockchip/yolov5 repository, the difference compared with the mainline repository is that the SiLU activation layer is replaced with the ReLU activation layer, and the post-processing part is handed over to the CPU for processing;
The model you plan to convert is obtained from other repositories, and there may be several operators in the model that are not supported and cause the conversion to fail, or there may be a reference dataset (parameter .. /dataset/50.txt) is not set correctly