edgetpu: ERROR: Didn't find op for builtin opcode 'TRANSPOSE_CONV' version '3'
Hi, I am trying to compile a model that uses tensorflow.keras.layers.Conv2DTranspos and get the following error:
$ edgetpu_compiler model_quant.tflite
Edge TPU Compiler version 2.1.302470888
ERROR: Didn't find op for builtin opcode 'TRANSPOSE_CONV' version '3'
ERROR: Registration failed.
Invalid model: model_quant.tflite
Model could not be parsed
I followed the Retrain a classification model using post-training quantization notebook. I’ve installed tf-nightly:
$ pip list | grep tf
tf-estimator-nightly 2.3.0.dev2020061401
tf-nightly 2.3.0.dev20200614
tflite-runtime 2.1.0.post1
Create a TensorFlow Lite model with TFLiteConverter.
The following creates a basic (un-quantized) TensorFlow Lite model:
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_path)
tflite_model = converter.convert()
with open('model.tflite', 'wb') as f:
f.write(tflite_model)
Convert the model again with post-training quantization:
dataset_dir = "path/to/dataset"
# A generator that provides a representative dataset
def representative_data_gen():
dataset_list = tf.data.Dataset.list_files(dataset_dir + '*.jpg')
dataset_list = dataset_list.take(110)
for i in range(100):
image = next(iter(dataset_list))
image = tf.io.read_file(image)
image = tf.io.decode_jpeg(image, channels=3)
image = tf.image.resize(image, [IMAGE_SIZE, IMAGE_SIZE])
image = tf.cast(image / 255., tf.float32)
image = tf.expand_dims(image, 0)
yield [image]
# This enables quantization
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_types = [tf.int8]
# This ensures that if any ops can't be quantized, the converter throws an error
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
# These set the input and output tensors to uint8 (added in r2.3)
converter.inference_input_type = tf.uint8 # also tried with tf.int8
converter.inference_output_type = tf.uint8 # also tried with tf.int8
# And this sets the representative dataset so we can quantize the activations
converter.representative_dataset = representative_data_gen
tflite_model = converter.convert()
with open('model_quant.tflite', 'wb') as f:
f.write(tflite_model)
Finally tried to compile the model_quant.tflite with the edgetpu-compiler (version 2.1.302470888) as mentioned above.
According to the documentation Transpose_CONV should be one of the supported operations.
Any idea how to fix this error? Thank you.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (1 by maintainers)
@Namburger thanks looking into this and the provided link. I’ve also tried using tensorflow 2.2 which results in the following error:
I am not using the model from the retrain script but my own. It contains:
I guess the problem is that
LeakyReLUis not supported? However, the error mentions:TRANSPOSE_CONVis not supported (when using tf-nightly 2.3).I’ll try to use ReLU instead of LeakyReLU and test with both tensorflow versions 2.2 and 2.3 (nightly).
@fjp I have an updates: The sweet spot is with
tensorflow2.2for our released compiler right now if you want to downgrade to that. FYI, you may need to uninstalltf-nightlycompletely and install tf2.2 😕Here is an example for making this model with
Conv2DTranspose(withtf2.1*the tflite converter fails because it wasn’t supported yet and withtf2.3*edgetpu_compiler fails):Note that these options are only available for
tensorflow2.3*and upTherefore, your IO tensors will still be float.
and compile:
Hope this helps 😃