tf.summary.image 似乎不适用于估算器预测
tf.summary.image seems not work for estimator prediction
我想在预测时使用 tf.estimator 可视化我的输入图像,但似乎 tf.summary.image 没有保存图像。但它适用于训练。
这是我在 model_fn 中的代码:
...
summary_hook = tf.train.SummarySaverHook(
save_secs=2,
output_dir='summary',
scaffold=tf.train.Scaffold(summary_op=tf.summary.merge_all()))
#summary_op=tf.summary.merge_all())
tf.summary.histogram("logit",logits)
tf.summary.image('feat', feat)
if mode == tf.estimator.ModeKeys.PREDICT:
return tf.estimator.EstimatorSpec(mode, predictions=preds, prediction_hooks=[summary_hook])
...
这是我的预测代码:
config = tf.estimator.RunConfig(save_summary_steps=0)
estimator = tf.estimator.Estimator(model_fn=model_fn, model_dir='logs', config=config)
preds = estimator.predict(input_fn=eval_input_fn)
使用tf.train.SummarySaverHook
有什么问题吗?
我假设您需要在 调用 merge_all
之前放置摘要操作 (histogram/image) ,以便 merge_all
实际上有一些东西合并。
...
tf.summary.histogram("logit",logits)
tf.summary.image('feat', feat)
summary_hook = tf.train.SummarySaverHook(
save_secs=2,
output_dir='summary',
scaffold=tf.train.Scaffold(summary_op=tf.summary.merge_all()))
#summary_op=tf.summary.merge_all())
if mode == tf.estimator.ModeKeys.PREDICT:
return tf.estimator.EstimatorSpec(mode, predictions=preds, prediction_hooks=[summary_hook])
...
我想在预测时使用 tf.estimator 可视化我的输入图像,但似乎 tf.summary.image 没有保存图像。但它适用于训练。
这是我在 model_fn 中的代码:
...
summary_hook = tf.train.SummarySaverHook(
save_secs=2,
output_dir='summary',
scaffold=tf.train.Scaffold(summary_op=tf.summary.merge_all()))
#summary_op=tf.summary.merge_all())
tf.summary.histogram("logit",logits)
tf.summary.image('feat', feat)
if mode == tf.estimator.ModeKeys.PREDICT:
return tf.estimator.EstimatorSpec(mode, predictions=preds, prediction_hooks=[summary_hook])
...
这是我的预测代码:
config = tf.estimator.RunConfig(save_summary_steps=0)
estimator = tf.estimator.Estimator(model_fn=model_fn, model_dir='logs', config=config)
preds = estimator.predict(input_fn=eval_input_fn)
使用tf.train.SummarySaverHook
有什么问题吗?
我假设您需要在 调用 merge_all
之前放置摘要操作 (histogram/image) ,以便 merge_all
实际上有一些东西合并。
...
tf.summary.histogram("logit",logits)
tf.summary.image('feat', feat)
summary_hook = tf.train.SummarySaverHook(
save_secs=2,
output_dir='summary',
scaffold=tf.train.Scaffold(summary_op=tf.summary.merge_all()))
#summary_op=tf.summary.merge_all())
if mode == tf.estimator.ModeKeys.PREDICT:
return tf.estimator.EstimatorSpec(mode, predictions=preds, prediction_hooks=[summary_hook])
...