TFLite Converter: Conv2D error when converting

Here is the code snippet I used:

    converter = tf.lite.TFLiteConverter.from_saved_model(self.tf_model_path)
    converter.experimental_new_converter = True
    converter.optimizations = [tf.lite.Optimize.DEFAULT]
    converter.target_spec.supported_ops = [
        tf.lite.OpsSet.TFLITE_BUILTINS_INT8,
        tf.lite.OpsSet.SELECT_TF_OPS]
    converter.inference_input_type = tf.int8
    converter.inference_output_type = tf.int8
    converter.representative_dataset = representative_dataset

    tflite_model = converter.convert()

File “torch2tflite/converter.py”, line 178, in tf2tflite
tflite_model = converter.convert()
File “/lib/python3.7/site-packages/tensorflow/lite/python/lite.py”, line 929, in wrapper
return self._convert_and_export_metrics(convert_func, *args, **kwargs)
File “/lib/python3.7/site-packages/tensorflow/lite/python/lite.py”, line 908, in _convert_and_export_metrics
result = convert_func(self, *args, **kwargs)
File “/lib/python3.7/site-packages/tensorflow/lite/python/lite.py”, line 1212, in convert
return self._convert_from_saved_model(graph_def)
File “/lib/python3.7/site-packages/tensorflow/lite/python/lite.py”, line 1097, in _convert_from_saved_model
result, quant_mode, quant_io=self.experimental_new_quantizer)
File “/lib/python3.7/site-packages/tensorflow/lite/python/convert_phase.py”, line 215, in wrapper
raise error from None # Re-throws the exception.
File “/lib/python3.7/site-packages/tensorflow/lite/python/convert_phase.py”, line 205, in wrapper
return func(*args, **kwargs)
File “/lib/python3.7/site-packages/tensorflow/lite/python/lite.py”, line 869, in _optimize_tflite_model
q_bias_type, q_allow_float)
File “/lib/python3.7/site-packages/tensorflow/lite/python/lite.py”, line 613, in _quantize
self.representative_dataset.input_gen)
File “/lib/python3.7/site-packages/tensorflow/lite/python/convert_phase.py”, line 215, in wrapper
raise error from None # Re-throws the exception.
File “/lib/python3.7/site-packages/tensorflow/lite/python/convert_phase.py”, line 205, in wrapper
return func(*args, **kwargs)
File “/lib/python3.7/site-packages/tensorflow/lite/python/optimize/calibrator.py”, line 226, in calibrate
self._feed_tensors(dataset_gen, resize_input=True)
File “/lib/python3.7/site-packages/tensorflow/lite/python/optimize/calibrator.py”, line 129, in _feed_tensors
self._calibrator.Prepare([list(s.shape) for s in input_array])
RuntimeError: tensorflow/lite/kernels/conv.cc:357 input_channel % filter_input_channel != 0 (1 != 0)Node number 8 (CONV_2D) failed to prepare.

1 Like

Hi, there is a github issue regarding grouped convolution with tflite.
Please see here:

I have the same issue. It does seem to happen when converting with a representative dataset (full integer quantization). Dynamic range quantization works without the problem. Coud you solve the issue @Natalia_A_Frumkin ?