首页 > 解决方案 > Py charm 冻结图未将 8 个变量转换为常量操作

问题描述

import tensorflow as tf

from tensorflow.python.tools import freeze_graph,optimize_for_inference_lib

# Saving the graph as a pb file taking data from pbtxt and ckpt files and providing a few operations
freeze_graph.freeze_graph('advanced_mnist.pbtxt',
                          '',
                          True,
                          'advanced_mnist.ckpt',
                          'h_readout1',
                          'save/restore_all',
                          'save/Const:0',
                          'frozen_advance_mnist.pb'
                          ,True,
                          '')
# Read the data form the frozen graph pb file

input_graph_def = tf.GraphDef()
with tf.gfile.Open('frozen_advance_mnist.pb','rb') as f:
    data = f.read()
    input_graph_def.ParseFromString(data)
# Optimize the graph with input and output nodes
output_graph_def = optimize_for_inference_lib.optimize_for_inference(input_graph_def,['x_input','keep_prob'],['h_readout1'],tf.float32.as_datatype_enum)
# Save the optimized graph to the optimized pb file
f = tf.gfile.FastGFile('optimized_advanced_mnist.pb','w')
f.write(output_graph_def.SerializeToString())

我尝试运行输入和输出,但文件没有将变量转换为任何常量操作,而是仅处理以退出代码 0 完成。

标签: python-3.xtensorflow

解决方案


推荐阅读