【问题标题】:How to generate .tf/.tflite files from python如何从 python 生成 .tf/.tflite 文件
【发布时间】:2021-08-26 10:09:54
【问题描述】:

我正在尝试生成我想用于我的移动应用程序的自定义张量流模型(tf/tflite 文件)。

我浏览了一些机器学习和张量流博客,从那里我开始生成一个简单的 ML 模型。

  1. https://www.datacamp.com/community/tutorials/tensorflow-tutorial
  2. https://www.edureka.co/blog/tensorflow-object-detection-tutorial/
  3. https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc
  4. https://www.youtube.com/watch?v=ICY4Lvhyobk

所有这些都非常好,他们指导我执行以下步骤,

i)安装所有必要的工具(TensorFlow、Python、Jupyter 等)。 ii) 加载训练和测试数据。 iii) 运行张量流会话进行训练并评估结果。 iv)提高准确性的步骤

但我无法生成 .tf/.tflite 文件。

我尝试了以下代码,但这会生成一个空文件。

converter = tf.contrib.lite.TFLiteConverter.from_session(sess,[],[]) 
model = converter.convert()

file = open( 'model.tflite' , 'wb' ) 
file.write( model )

我在 stackoverflow 中检查了几个答案,根据我的理解,为了生成 .tf 文件,我们需要创建 pb 文件,冻结 pb 文件,然后生成 .tf 文件。

但是我们怎样才能做到这一点呢?

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    Tensorflow 提供 Tflite 转换器将保存的模型转换为 Tflite 模型。更多详细信息请查找here

    tf.lite.TFLiteConverter.from_saved_model() (recommended): Converts a SavedModel.
    
    tf.lite.TFLiteConverter.from_keras_model(): Converts a Keras model.
    
    tf.lite.TFLiteConverter.from_concrete_functions(): Converts concrete functions.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 2021-11-08
      • 2019-04-19
      • 1970-01-01
      • 2016-03-20
      • 2023-02-25
      相关资源
      最近更新 更多