返回tf.estimator.evaluate()上的标签和预测,除了丢失

时间:2018-06-06 09:14:40

标签: python tensorflow machine-learning tensorflow-estimator

我希望运行一个tf.estimator.Estimator model_fn,在tf.estimator.ModeKeys.EVAL下调用时,不仅会返回丢失,还会返回具有预测张量和标签张量的字典(也就是真相) )。 我正在尝试回归图像,因此我可以直观地了解输入/预测质量。

如果我在model_fn

中运行代码
predictions = {
    "predictions": td.last()  # return the last tensor (prediction)
}

if mode == tf.estimator.ModeKeys.PREDICT:
    # wrap predictions into a class and return EstimatorSpec object
    return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)

# minimize on cross-entropy
loss = tf.losses.mean_squared_error(labels=labels, predictions=td.last())  # loss is a scalar tensor

if mode == tf.estimator.ModeKeys.EVAL:
    predictions['truth'] = tf.convert_to_tensor(labels, dtype=tf.float32)
    # wrap predictions into a class and return EstimatorSpec object
    return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions, loss=loss)

TensorFlow在评估时运行时会忽略返回的EstimatorSpec中的预测参数。在预测上运行时,标签不可用。

你知道有没有办法做到这一点?

谢谢!

0 个答案:

没有答案