使用tensorflow将图形和权重保存在文件中

时间:2017-09-12 20:38:59

标签: python tensorflow

我正在尝试使用训练模型在tensorflow上保存文件,我正在尝试使用这个简单的图表:

import tensorflow as tf

a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b  # + provides a shortcut for tf.add(a, b).

builder = tf.saved_model_builder.SavedModelBuilder(".")

sess = tf.Session()
builder.add_meta_graph([tag_constants.SERVING])
builder.save()

print(sess.run(adder_node, {a: 3, b: 4.5}))
print(sess.run(adder_node, {a: [1, 3], b: [2, 4]}))

但它给了我一个错误:

AttributeError: 'module' object has no attribute 'saved_model_builder'

说它在tensorflow模块中不存在,我遵循了这个官方教程:https://www.tensorflow.org/programmers_guide/saved_model

如何在tensorflow中保存训练好的模型?

1 个答案:

答案 0 :(得分:9)

教程未更新,请将tf.saved_model_builder.SavedModelBuilder更改为tf.saved_model.builder.SavedModelBuilder