So, looks like situation evolved, now quantization aware training is not required anymore.
With that:
converter = tf.lite.TFLiteConverter(frozen_graph, input_tensors=inputs.values(), output_tensors=outputs.values())
converter.post_training_quantize = True
+ converter.inference_type = tf.lite.constants.QUANTIZED_UINT8
+ converter.quantized_input_stats = {
+ 'input_samples': (0., 1.),
+ 'Reshape': (0., 1.),
+ 'previous_state_c': (0., 1.),
+ 'previous_state_h': (0., 1.),
+ }
+ converter.default_ranges_stats = (0, 128)
# AudioSpectrogram and Mfcc ops are custom but have built-in kernels in TFLite
converter.allow_custom_ops = True
tflite_model = converter.convert()
@@ -596,12 +596,6 @@ def test():
def create_inference_graph(batch_size=1, n_steps=16, tflite=False):
batch_size = batch_size if batch_size > 0 else None
- # Create feature computation graph
- input_samples = tfv1.placeholder(tf.float32, [Config.audio_window_samples], 'input_samples')
- samples = tf.expand_dims(input_samples, -1)
- mfccs, _ = samples_to_mfccs(samples, FLAGS.audio_sample_rate)
- mfccs = tf.identity(mfccs, name='mfccs')
-
# Input tensor will be of shape [batch_size, n_steps, 2*n_context+1, n_input]
# This shape is read by the native_client in DS_CreateModel to know the
# value of n_steps, n_context and n_input. Make sure you update the code
I can get the model converted for EdgeTPU. Now, we still need to take care of AudioSpectrogram and Mfcc operators on CPU.