我想将存储在硬盘中的冻结模型转换为model.ckpt。这里是我的代码,但它会产生一些错误,这是怎么回事?
import tensorflow
from tensorflow import gfile
graph = tensorflow.get_default_graph()
with graph.as_default():
forzen_graph_file = "frozen_inference_graph_opt.pb"
with gfile.FastGFile(forzen_graph_file, 'rb') as tf_model:
tf_graph = tensorflow.GraphDef()
tf_graph.ParseFromString(tf_model.read())
with tensorflow.Session(graph=tensorflow.Graph) as sess:
saver = tensorflow.train.Saver()
# obtain the corresponding input-output tensor
tensorflow.import_graph_def(tf_graph, name='')
save_path = saver.save(sess, "model.ckpt")
这是错误:
更新说明:
使用tf.gfile.GFile。
回溯(最近通话最近):
文件“ /home/pedram/Desktop/fast-semantic-segmentation-master/test.py”,行 13,在
with tensorflow.Session(graph=tensorflow.get_default_graph) as sess:
在 init
中的文件“ /usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”,第1551行super(Session, self).__init__(target, graph, config=config)
init
中的文件“ /usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”,行643。raise TypeError('graph must be a tf.Graph, but got %s' % type(graph))
类型错误:图形必须是tf.Graph,却得到了
Exception AttributeError:“'Session'对象没有属性 在 '_session'”> 已忽略