我正在尝试将使用Keras构建和训练的模型导出到我可以在C++脚本中加载的protobuffer(如本例所示).我生成了一个包含模型定义的.pb文件和一个包含检查点数据的.ckpt文件.但是,当我尝试使用freeze_graph脚本将它们合并到一个文件中时,我收到错误:
ValueError: Fetch argument 'save/restore_all' of 'save/restore_all' cannot be interpreted as a Tensor. ("The name 'save/restore_all' refers to an Operation not in the graph.")
Run Code Online (Sandbox Code Playgroud)
我正在保存这样的模型:
with tf.Session() as sess:
model = nndetector.architecture.models.vgg19((3, 50, 50))
model.load_weights('/srv/nn/weights/scratch-vgg19.h5')
init_op = tf.initialize_all_variables()
sess.run(init_op)
graph_def = sess.graph.as_graph_def()
tf.train.write_graph(graph_def=graph_def, logdir='.', name='model.pb', as_text=False)
saver = tf.train.Saver()
saver.save(sess, 'model.ckpt')
Run Code Online (Sandbox Code Playgroud)
nndetector.architecture.models.vgg19((3,50,50))只是一个在Keras中定义的类似vgg19的模型.
我正在调用freeze_graph脚本:
bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=[path-to-model.pb] --input_checkpoint=[path-to-model.ckpt] --output_graph=[output-path] --output_node_names=sigmoid --input_binary=True
Run Code Online (Sandbox Code Playgroud)
如果我运行freeze_graph_test脚本一切正常.
有谁知道我做错了什么?
谢谢.
最好的祝福
菲利普
编辑
我试过打印tf.train.Saver().as_saver_def().restore_op_name返回save/restore_all.
另外,我尝试了一个简单的纯tensorflow示例,仍然得到相同的错误:
a = tf.Variable(tf.constant(1), name='a')
b = tf.Variable(tf.constant(2), …Run Code Online (Sandbox Code Playgroud) tensorflow ×1