Converting tflite model failed with error

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu

Which version of system do you use? Please provide the version of the system here:

Ubuntu 22.04

Please describe your issue below:

I tried to convert the TFLITE model to ADLA and run it.

On Python, this model worked fine.

The input to the model was (3,128,128), as shown below.
So I put the same (3,128,128) in the conversion script.

The ERROR Message says that the image shape and input shape are different.

How can we solve this problem?

Post a console log of your issue below:

TFLITE In/Out Tensor info

=== Input Tensor ===
name                : serving_default_input:0
index               : 0
shape               : [  1   3 128 128]
shape_signature     : [ -1   3 128 128]
dtype               : <class 'numpy.float32'>
quantization        : (0.0, 0)
quantization_parameters: {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}
sparsity_parameters : {}

=== Output Tensor ===
name                : PartitionedCall:0
index               : 147
shape               : [1 8]
shape_signature     : [-1  8]
dtype               : <class 'numpy.float32'>
quantization        : (0.0, 0)
quantization_parameters: {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}
sparsity_parameters : {}

Convert Script

$adla_convert --model-type tflite \
        --model ./my_model.tflite \
        --inputs "serving_default_input:0" \
        --input-shapes  "3,128,128" \
        --dtypes "float32" \
        --quantize-dtype int8 \
        --outdir tflite \
	    --channel-mean-value "0,0,0,255" \
	    --inference-input-type "float32" \
        --inference-output-type "float32" \
	    --source-file "dataset_128_128.txt"  \
        --batch-size 1 --target-platform PRODUCT_PID0XA003

Converting ERROR Message


I Quantize_info: input_type:<dtype: 'float32'>, quant_type:int8, output_type:<dtype: 'float32'>, disable_per_channel:True, quantizer:True
weights_quantize:0,opt_algo:1,thres_size:4,scale:0.999,iterations:500,iterations_num:10
I Quantize_info: rep_data_gen shape:[[1, 3, 128, 128]], source_file:dataset_128_128.txt,g_channel_mean_value(Only valid for pictures):[[0.0, 0.0, 0.0, 255.0]]
E image[./data_128_128/1.jpg] channel not equal to model input channel,img_shape:(3, 128, 3),shape:[1, 3, 128, 128]
I ----------------Warning(0)----------------
E image[./data_128_128/1.jpg] channel not equal to model input channel,img_shape:(3, 128, 3),shape:[1, 3, 128, 128]
I ----------------Warning(0)----------------

...

Traceback (most recent call last):
  File "tvm/adla_convert.py", line 185, in <module>
  File "tvm/adla_convert.py", line 180, in main
  File "tvm/contrib/target/adla_interface.py", line 87, in convert
  File "tvm/adlalog.py", line 209, in e
ValueError: image[./data_128_128/1.jpg] channel not equal to model input channel,img_shape:(3, 128, 3),shape:[1, 3, 128, 128]
[6224] Failed to execute script 'adla_convert' due to unhandled exception!

When replacing model type value with quantized_tflite,
or when replacing input-shapes value to “128,128,3”,
I got the following result

I Adla_tool: step_0 enter, begin to load original model.
I Adla_tool: step_0 out, load original model successfully.
I Adla_tool: step_1 enter, begin to convert model to ir.
I Adla_tool: step_1 out, convert model to ir successfully.
I Adla_tool: step_2 enter, begin to convert adla_file.
I target ADLA HW (r2p0) does not support Conv2d with the input type of FP32 (node 2)
failed to preprocess the input model
failed to compile "alignment_v2.ir"

Hi @GHdevlog

@Louis-Cheng-Liu will help you later.

Regards,
Nick

Hello @GHdevlog ,

Could you provide your model?

Here’s my model.

Hello @GHdevlog ,

The default TFLite input size of the conversion tool is (1, height, width, channel). But your model input is (1, channel, height, width).

In your model, there are many pad layer. It always transpose berfore and after padding. But the first pad after input, it has not transpose which makes model input is (1, channel, height, width).

Add a transpose layer after input or delete the first pad layer and tranpose layer in TensorFlow model and then covnert it to TFLite.

1 Like