0

I am trying to quantizate a tensoflow graph stored in .pb. The input of the network is a matrix, that each row is normalized with mean 0 and std 1. I want to create a tensorflow-lite model quantizate to inteference faster. I do not know how to pass the inputs to the line conversion. Is it a just one value? a vector with 64 values? how is it passed?

The model is well converted without quantization.

tflite_convert \
    --output_file=model_simple_weight_q.tflite \
    --graph_def_file=model_simple.pb \
    --inference_type=QUANTIZED_UINT8 \
    --input_arrays=input \
    --output_arrays=LogSoftmax \
    --mean_values= # dont know  \
    --std_dev_values=# dont know

If I pass two single values, --mean_values=127 and --std_dev_values=128 for instance. Just to know what happens, I get the following error:

F tensorflow/lite/toco/graph_transformations/resolve_constant_gather.cc:108] Check failed: coords_array.data_type == ArrayDataType::kInt32 Only int32 indices are supported
Aborted (core dumped)

2 Answers2

0

The error you are seeing is not related to mean/std_dev values. It is an error while converting your graph in general. It is saying that in one of your graph operations, an index is used in a tf.gather (or maybe a slicing) and it has a type that is not int32, but that's the only supported index type.

Unfortunately the TFLite conversion errors will often not tell you the source code that caused the error, so you'll have to make informed guesses.

Regards mean/std_dev values, I suggest you take a look at this answer : https://stackoverflow.com/a/58096430/834565

MohamedEzz
  • 2,830
  • 3
  • 20
  • 26
0

As each row of the input is normalized with mean 0 and std 1, you should give --mean_values=0 and --std_dev_values=1 . Also, when you are doin a 'Dummy post traing quantization', you need to provide the minimum and maximum range for the activation functions. You need to provide --default_ranges_min= and --default_ranges_max= .

As tensorflow doesn't provide very clear describtion about how to calculate the activation range, it is better to do 'post training full integer quantization' with a small calibration data- here . In this methode the range of the activation function are calculated with the calibration images.

Regards,

MMH
  • 1,676
  • 5
  • 26
  • 43