Full-quatization Does Not Except Int8 Data To Change Model Input Layer To Int8
I am quantizing a keras h5 model to uint8. To get full uint8 quatization, user dtlam26 told me in this post that the representative dataset should already be in uint8, otherwise th
Solution 1:
SOLUTION from user dtlam26
Even though the model still does not run with the google NNAPI, the solution to quantize the model with in and output in int8 using either TF 1.15.3 or TF2.2.0 is, thanks to delan:
...
converter = tf.lite.TFLiteConverter.from_keras_model_file(saved_model_dir + modelname)
defrepresentative_dataset_gen():
for _ inrange(10):
pfad='pathtoimage/000001.jpg'
img=cv2.imread(pfad)
img = np.expand_dims(img,0).astype(np.float32)
# Get sample input data as a numpy array in a method of your choosing.yield [img]
converter.representative_dataset = representative_dataset_gen
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset_gen
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.experimental_new_converter = True
converter.target_spec.supported_types = [tf.int8]
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
quantized_tflite_model = converter.convert()
if tf.__version__.startswith('1.'):
open("test153.tflite", "wb").write(quantized_tflite_model)
if tf.__version__.startswith('2.'):
withopen("test220.tflite", 'wb') as f:
f.write(quantized_tflite_model)
Post a Comment for "Full-quatization Does Not Except Int8 Data To Change Model Input Layer To Int8"