我有一个想要在 Coral Edge TPU 设备上运行的 Keras 模型。为此,它需要是具有全整数量化的 Tensorflow Lite 模型。我能够将模型转换为 TFLite 模型:
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)
但是当我运行时edgetpu_compiler converted_model.tflite
,我得到了这个错误:
Edge TPU Compiler version 2.0.267685300
Invalid model: converted_model.tflite
Model not quantized
这是因为我需要量化模型,但我不知道该怎么做。我发现这个页面告诉我如何做到这一点,但它希望我制作一个输入数据生成器。这是它提供的示例:
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]
如何调整此代码以处理我的输入数据?从哪里来num_calibration_steps
?有一个更好的方法吗?(我看到了参考,tf.contrib.tpu.keras_to_tpu_model
但它已被弃用)