张量流冻结模型仅包含输出占位符变量



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

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

为什么模型中没有包含所有图形和变量?

我使用了下面派生自 https://github.com/sankit1/cv-tricks.com/tree/master/Tensorflow-tutorials/freeze_model_and_deploy 的代码。它适用于其他模型,但不适用于我的模型。

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 中,但无法将它们带到那里。

您遵循的链接是冻结张量流模型的正确过程。

冻结模型会减小模型的大小,因为它只会保存您提供给它的"output_node_names"存储。

有关整个过程,请参阅以下链接。 https://cv-tricks.com/how-to/freeze-tensorflow-models/

在这里,您能否详细说明"pos"是什么?

此外,如果您在这里传递预测操作,因为这是预测所需的最终操作,它应该可以正常工作。

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

最新更新