在其他文件中加载 Tensorflow Graph 不提供相同的准确性
Loading Tensorflow Graph in other file not giving the same accuracy
我在 Tensorflow 中训练了一个 CNN,它的测试准确率为 92%。我将其保存为典型的 ckpt 文件。
session = tf.Session(config=tf.ConfigProto(log_device_placement=True))
session.run(tf.global_variables_initializer())
<TRAINING ETC>
saver.save(session, save_path_name)
在另一个文件中,我想 运行 推理,所以我按照文档中的说明调用元图:
face_recognition_session = tf.Session()
saver = tf.train.import_meta_graph(<PATH TO META FILE>, clear_devices=True)
saver.restore(face_recognition_session, <PATH TO CKPT FILE>)
graph = tf.get_default_graph()
x = graph.get_tensor_by_name('input_variable_00:0')
y = graph.get_tensor_by_name('output_variable_00:0')
进行推理或重新测试时,准确率下降到 3%。
我是不是忽略了什么?
您将错误的方法分配给 saver
。从 TF Guide 你可以看到你想初始化会话然后通过 tensorflow.train.Saver()
.
上传
tf.reset_default_graph()
# Create some variables.
x = tf.get_variable("input_variable_00:0", [x_shape])
y = tf.get_variable("output_variable_00:0", [y_shape])
saver = tf.train.Saver()
# Use the saver object normally after that.
with tf.Session() as sess:
# Initialize v1 since the saver will not.
saver.restore(sess, <PATH TO CKPT FILE>)
print("x : %s" % x.eval())
print("y : %s" % y.eval())
如果您想获得一致的推理结果,我还建议您将 freezing and exporting your graphs 作为 GraphDef
进行研究。
我在 Tensorflow 中训练了一个 CNN,它的测试准确率为 92%。我将其保存为典型的 ckpt 文件。
session = tf.Session(config=tf.ConfigProto(log_device_placement=True))
session.run(tf.global_variables_initializer())
<TRAINING ETC>
saver.save(session, save_path_name)
在另一个文件中,我想 运行 推理,所以我按照文档中的说明调用元图:
face_recognition_session = tf.Session()
saver = tf.train.import_meta_graph(<PATH TO META FILE>, clear_devices=True)
saver.restore(face_recognition_session, <PATH TO CKPT FILE>)
graph = tf.get_default_graph()
x = graph.get_tensor_by_name('input_variable_00:0')
y = graph.get_tensor_by_name('output_variable_00:0')
进行推理或重新测试时,准确率下降到 3%。
我是不是忽略了什么?
您将错误的方法分配给 saver
。从 TF Guide 你可以看到你想初始化会话然后通过 tensorflow.train.Saver()
.
tf.reset_default_graph()
# Create some variables.
x = tf.get_variable("input_variable_00:0", [x_shape])
y = tf.get_variable("output_variable_00:0", [y_shape])
saver = tf.train.Saver()
# Use the saver object normally after that.
with tf.Session() as sess:
# Initialize v1 since the saver will not.
saver.restore(sess, <PATH TO CKPT FILE>)
print("x : %s" % x.eval())
print("y : %s" % y.eval())
如果您想获得一致的推理结果,我还建议您将 freezing and exporting your graphs 作为 GraphDef
进行研究。