Here is my converter code:
def representative_dataset_gen():
for i in range(len(test_list)):
if(i>300):
break
print(i)
wavpath=test_path + test_list[i]
x, sr = librosa.load(wavpath, sr=16000, mono=False)
noisy = x[1, :]
Complex_spec=WOLA_calculate(noisy).astype(np.float32)
Complex_spec=Complex_spec.transpose(0,3,1,2)
real=Complex_spec[:,0]
imag=Complex_spec[:,1]
spec_mag=np.sqrt(real ** 2 + imag ** 2)
spec_mag=spec_mag[:,:,:5000]
#print(X)
yield [spec_mag]
converter = tf.lite.TFLiteConverter.from_keras_model(lstm_tf) # path to the SavedModel directory
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset =representative_dataset_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS,tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
tflite_quant_model = converter.convert()
# Save the model.
with open('model_5000_represent.tflite', 'wb') as f:
f.write(tflite_quant_model)
I calcute the mask error between float model and converted int8 model,the mean error is 0.77,but i use dynamic converter,the mask error is 0.02,why calibration result get worse?