2

freeze_graph用来将我的模型导出到一个名为"frozen.pb". 但是发现预测的准确率frozen.pb很差。

我知道问题可能MovingAverage不包含在frozen.pb.

当我使用model.ckpt文件恢复模型进行评估时,如果我调用tf.train.ExponentialMovingAverage(0.999),则准确度符合预期,否则准确度很差。

那么如何导出与从检查点文件恢复的性能相同的二进制模型呢? 我想".pb"在 Android 设备中使用文件。

官方文档没有提到这一点。

谢谢!!

冻结命令:

~/bazel-bin/tensorflow/python/tools/freeze_graph \
  --input_graph=./graph.pbtxt \
  --input_checkpoint=./model.ckpt-100000 \
  --output_graph=frozen.pb \
  --output_node_names=output  \
  --restore_op_name=save/restore_all \
  --clear_devices

评估代码:

... ...
logits = carc19.inference(images)
top_k = tf.nn.top_k(logits, k=10)

# Precision: 97%
# Restore the moving average version of the learned variables for eval.
variable_averages = tf.train.ExponentialMovingAverage(carc19.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
for k in variables_to_restore.keys():
  print (k,variables_to_restore[k])
saver = tf.train.Saver(variables_to_restore)

# Precision: 84%
#saver = tf.train.Saver()

#model_path = '/tmp/carc19_train/model.ckpt-9801'
with tf.Session() as sess:
  saver.restore(sess, model_path)
... ...
4

0 回答 0