Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow冻结模型仅包含输出占位符变量_Python_Tensorflow - Fatal编程技术网

Python Tensorflow冻结模型仅包含输出占位符变量

Python Tensorflow冻结模型仅包含输出占位符变量,python,tensorflow,Python,Tensorflow,我试图冻结一个预先训练过的模型,然后在TF Lite中将其转换,并将其部署到Android设备中 通过使用xxd检查生成的.pb文件,我发现它只包含占位符输出变量。.pb的大小是几个字节 为什么模型中不包括所有的图形和变量 我使用了下面的源代码。它与其他车型配合得很好,但与我的车型不配合 import tensorflow as tf from tensorflow.python.framework import graph_util import os,sys path = './model

我试图冻结一个预先训练过的模型,然后在TF Lite中将其转换,并将其部署到Android设备中

通过使用xxd检查生成的.pb文件,我发现它只包含占位符输出变量。.pb的大小是几个字节

为什么模型中不包括所有的图形和变量

我使用了下面的源代码。它与其他车型配合得很好,但与我的车型不配合

import tensorflow as tf
from tensorflow.python.framework import graph_util
import os,sys

path = './model-gaze/'
output_node_names = "pos"
model_name = 'model-23'

saver = tf.train.import_meta_graph(path+model_name+'.meta', clear_devices=True)

graph = tf.get_default_graph()
input_graph_def = graph.as_graph_def()
sess = tf.Session()
saver.restore(sess, path+model_name)
output_graph_def = graph_util.convert_variables_to_constants(
            sess, # The session is used to retrieve the weights
            input_graph_def, # The graph_def is used to retrieve the nodes 
            output_node_names.split(",") # The output node names are used to select the usefull nodes
) 
output_graph=path+model_name+".pb"
with tf.gfile.GFile(output_graph, "wb") as f:
    f.write(output_graph_def.SerializeToString())

sess.close()

我希望所有的权重和图形数据都包含在.pb中,但无法将它们放到那里。

您下面的链接是冻结tensorflow模型的正确步骤

冻结模型会减小模型的大小,因为它只保存您给它存储的“输出节点名称”

请参考以下链接了解整个流程。

在这里,你能详细说明一下“pos”是什么吗

此外,如果您在这里通过了预测操作,因为这是预测所需的最终操作,那么它应该可以正常工作

如果这没有帮助,请共享您的模型和保存模型的代码,以进一步调试问题