使用SessionRunHook()或验证监视器在Tensorflow中提前停止

使用SessionRunHook()或验证监视器在Tensorflow中提前停止,tensorflow,Tensorflow,我有一个运行良好的深层神经网络。但是,添加以下代码以建立提前停止会导致错误: validation_metrics = { "accuracy": tf.contrib.learn.MetricSpec( metric_fn=tf.contrib.metrics.streaming_accuracy, prediction_key=tf.contrib.learn.prediction_key.PredictionKey. CLASSES)

我有一个运行良好的深层神经网络。但是,添加以下代码以建立提前停止会导致错误:

validation_metrics = {
"accuracy":
    tf.contrib.learn.MetricSpec(
        metric_fn=tf.contrib.metrics.streaming_accuracy,
        prediction_key=tf.contrib.learn.prediction_key.PredictionKey.
        CLASSES)}


validation_monitor = tf.contrib.learn.monitors.ValidationMonitor(
x=X_test, y=y_test, early_stopping_rounds=50, metrics=validation_metrics)
输出:

prediction_key=tf.contrib.learn.prediction_key.PredictionKey.CLASSES)}
AttributeError: module 'tensorflow.contrib.learn' has no attribute 'prediction_key'

您可以尝试以下操作:

prediction_key=tf.contrib.learn.PredictionKey.CLASSES
所有监视器都已关闭


你最好的办法就是看看。在撰写本文时,只有香草钩子可用。因此,您需要实现。

是否可以添加更多有关出错原因的详细信息,并查看是否可以减少重现错误所需的代码示例的大小?这将有助于我们更好地回答这个问题。谢谢-减少原始问题中的代码。完整代码要点:您使用的是什么版本的tensorflow和python?Python3.6,为GPU启用了TF'1.1.0-rc2'。