rockchip-linux / rknn-toolkit2

BSD 3-Clause "New" or "Revised" License
841 stars 152 forks source link

Convertion Error: automatically change batch size (TFLite convert to RKNN) #202

Open KihongK opened 11 months ago

KihongK commented 11 months ago

I trying to convert TFLite to RKNN (official tensorflow mobilenet)

I tested Demo tutorial script rknn-toolkit/tflite/mobilenet_v1 and It works well

Platform OS - GCP VM Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1110-gcp x86_64) Python 3.6.9

Modules torch 1.10.1 onnx 1.10.0 onnxruntime 1.10.0 rknn-toolkit2 version: 1.5.0+1fa95b5c

My Python Script

    # Create RKNN object
    rknn = RKNN(verbose=True)

    # Pre-process config
    print('--> Config model')
    rknn.config(optimization_level = 2, target_platform="rk3588")
#    rknn.config(mean_values=[128, 128, 128], std_values=[128, 128, 128])
    print('done')

    # Load model
    print('--> Loading model')
    ret = rknn.load_tflite(model=model_name, input_is_nchw = False)
    if ret != 0:
        print('Load model failed!')
        exit(ret)
    print('done')

    # Build model
    print('--> Building model')
    ret = rknn.build(do_quantization=False, rknn_batch_size = 1)
    if ret != 0:
        print('Build model failed!')
        exit(ret)
    print('done')

But keep occur input layer error at Loading model

W __init__: rknn-toolkit2 version: 1.5.0+1fa95b5c

--> Config model  
done  

--> Loading model  
2023-08-17 02:15:06.320817: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/kkhong/.local/lib/python3.6/site-packages/cv2/../../lib64:  
2023-08-17 02:15:06.320859: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.  

E load_tflite: The shape ['unk__833', 112, 112, 3] of 'serving_default_input_1:0' is not support! Please use the 'inputs' / 'input_size_list' of load_onnx to set the correct shape!  

W load_tflite: ===================== WARN(1) =====================  

E rknn-toolkit2 version: 1.5.0+1fa95b5c  
E load_tflite: Catch exception when loading tflite model: /home/kkhong/rknn-toolkit2/examples/tflite/face/test.tflite!  
E load_tflite: Traceback (most recent call last):  
E load_tflite:   File "rknn/api/rknn_base.py", line 1626, in rknn.api.rknn_base.RKNNBase.load_tflite  
E load_tflite:   File "rknn/api/rknn_base.py", line 658, in rknn.api.rknn_base.RKNNBase._create_ir_and_inputs_meta  
E load_tflite:   File "rknn/api/ir_graph.py", line 58, in rknn.api.ir_graph.IRGraph.__init__  
E load_tflite:   File "rknn/api/ir_graph.py", line 453, in rknn.api.ir_graph.IRGraph.rebuild  
E load_tflite:   File "rknn/api/rknn_log.py", line 112, in rknn.api.rknn_log.RKNNLog.e  
E load_tflite: ValueError: The shape ['unk__833', 112, 112, 3] of 'serving_default_input_1:0' is not support! Please use the 'inputs' / 'input_size_list' of load_onnx to set the correct shape!  
W If you can't handle this error, please try updating to the latest version of the toolkit2 and runtime from:  
  https://eyun.baidu.com/s/3eTDMk6Y (Pwd: rknn)  Path: RK_NPU_SDK / RK_NPU_SDK_1.X.0 / 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)
Load model failed!

How to fix this problem?? Should i convert onnx??

KihongK commented 11 months ago

and I checked model using netron

input layer shape is [1, 112, 112, 3]