I have a Keras model that I want to run on the Coral Edge TPU device. To do this, it needs to be a Tensorflow Lite model with full integer quantization. I was able to convert the model to a TFLite model:
model.save('keras_model.h5')
converter = tf.lite.TFLiteConverter.from_keras_model_file("keras_model.h5")
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
But when I run edgetpu_compiler converted_model.tflite
, I get this error:
Edge TPU Compiler version 2.0.267685300
Invalid model: converted_model.tflite
Model not quantized
This is because I need to quantize the model, but I'm not sure how to do that. I found this page which tells me how to do this, but it wants me to make an input data generator. This is the example it provides:
def representative_dataset_gen():
for _ in range(num_calibration_steps):
# Get sample input data as a numpy array in a method of your choosing.
yield [input]
How can I adapt this code to work with my input data? Where does num_calibration_steps
come from? Is there a better way to do this? (I saw references to tf.contrib.tpu.keras_to_tpu_model
but it has been deprecated)