【问题标题】:Problem converting tensorflow model to lite version将张量流模型转换为精简版的问题
【发布时间】:2019-10-02 07:34:49
【问题描述】:

我已经成功创建了一个 TensorFlow 模型,通过自定义操作保存为 SavedModel .pb 格式。

我的问题是我无法使用命令行实用程序或 python API 将其转换为精简版

我的 python API 是:

import tensorflow as tf 
import os
import custom_op

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

converter = tf.lite.TFLiteConverter.from_saved_model("./SavedModel")
converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,
                        tf.lite.OpsSet.SELECT_TF_OPS] 

tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

但转换失败并出现错误:

ValueError: Provide an input shape for input array 'X'.

我假设是因为我的占位符没有形状类型。我不明白为什么普通的 TensorFlow 模型没有它。

有什么帮助吗?

【问题讨论】:

    标签: tensorflow tensorflow-lite


    【解决方案1】:

    正如 TensorFlow Lite 的 documentation 中所述,您可以在 tf.lite.TFLiteConverter.from_saved_model 中传递不同的参数。

    对于更复杂的 SavedModel,可以传入TFLiteConverter.from_saved_model() 的可选参数是input_arrays, input_shapes, output_arrays, tag_set and signature_key。运行help(tf.lite.TFLiteConverter)可以查看每个参数的详细信息。

    您可以按照here 的说明传递此信息。您需要为输入数组“X”提供输入形状。喜欢,

    tf.lite.TFLiteConverter.from_saved_model("./Saved_model", input_shapes={("X" : [1,H,W,C])})
    

    【讨论】:

    • 好的,然后我需要修复创建模型的代码。在那里我有:# tf Graph Input X = tf.compat.v1.placeholder(tf.float32, name='X') Y = tf.compat.v1.placeholder(tf.float32, name='Y') 我必须弄清楚形状参数应该是什么。到目前为止,除了上述代码之外,我尝试过的任何操作都引发了异常
    猜你喜欢
    • 1970-01-01
    • 2018-11-25
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多