【问题标题】:Does TFLiteConverter automatically quantize the Keras model?TFLiteConverter 会自动量化 Keras 模型吗?
【发布时间】:2019-08-22 12:26:06
【问题描述】:

我使用 tf.lite.TFLiteConverter 将经过训练的 Keras 模型转换为 tflite_model。转换后的 tflite_model 是量化的吗?这是进行转换的sn-p。

import tensorflow as tf

keras_model = "./Trained_Models/h_vs_o_a_V1.h5"

converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_model)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

【问题讨论】:

  • 要启用模型量化,我们需要添加以下标志~> converter.post_training_quantize = True
  • 在哪里插入代码?是在 tflite_model = converter.convert() 之前吗?

标签: tensorflow quantization


【解决方案1】:

基本上,在使用converter.convert() 进行转换之前,我们需要converter.post_training_quantize = True 标志,

import tensorflow as tf

keras_model = "./Trained_Models/h_vs_o_a_V1.h5"

converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_model)
converter.post_training_quantize = True
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多