我已经训练了一个自定义的Keras网络,我想把它部署在一个MCU上。我必须将它量化为UINT8。
model = tf.keras.models.load_model('saved_model/MaskNet_extended.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = [tf.uint8]
converter.inference_output_type = [tf.uint8]
converter.representative_dataset = rep_ds
tflite_quant_model = converter.convert()
问题是tf_lite_quant_model仍然是Float32.这怎么可能?
网络是。
model = Sequential([
Conv2D(16, 3, padding='same', activation='relu',
input_shape=(IMG_SHAPE)),
MaxPooling2D(),
Conv2D(32, 3, padding='same', activation='relu'),
MaxPooling2D(),
Conv2D(64, 3, padding='same', activation='relu'),
MaxPooling2D(),
Flatten(),
Dense(512, activation='relu'),
Dense(1, activation = 'sigmoid')
])
这是在TFLiteConverterV2中已知的问题,有一个变通的方法可以解决它 https:/github.comtensorflowtensorflowblobmastertensorflowlitetoolsoptimizepythonmodify_model_interface.py。.
TensorFlow Lite也将很快输出uint8。