【问题标题】:How to use a ValidationMonitor for an Estimator in TensorFlow 1.0?如何在 TensorFlow 1.0 中将 ValidationMonitor 用于 Estimator?
【发布时间】:2017-03-13 13:49:39
【问题描述】:

TensorFlow 提供了将 ValidationMonitors 与几个预定义的估计器(如 tf.contrib.learn.DNNClassifier)结合起来的可能性。 但我想为我自己的估算器使用 ValidationMonitor,它是基于 1 创建的。

对于我自己的估算器,我首先初始化一个 ValidationMonitor:

validation_monitor = tf.contrib.learn.monitors.ValidationMonitor(testX,testY,every_n_steps=50)

estimator = tf.contrib.learn.Estimator(model_fn=model,model_dir=direc,config=tf.contrib.learn.RunConfig(save_checkpoints_secs=1))

input_fn = tf.contrib.learn.io.numpy_input_fn({"x": x}, y, 4, num_epochs=1000)

这里我通过监视器如2 for tf.contrib.learn.DNNClassifier 所示:

estimator.fit(input_fn=input_fn, steps=1000,monitors=[validation_monitor])

这失败并打印了以下错误:

ValueError:功能与给定信息不兼容。给定特征:Tensor("input:0", shape=(?, 1), dtype=float64),所需签名:{'x': TensorSignature(dtype=tf.float64, shape=TensorShape([Dimension(None)] ), is_sparse=False)}。


我如何将监视器用于我自己的估算器?
谢谢。

【问题讨论】:

    标签: machine-learning tensorflow


    【解决方案1】:

    将包含 testXtestYinput_fn 传递给 ValidationMonitor 而不是传递张量 时问题得到解决>testXtestY 直接。

    【讨论】:

      【解决方案2】:

      作为记录,您的错误是由于 ValidationMonitor 期望 x 是像 { 'feature_name_as_a_string' : feature_tensor } 这样的字典,而在您的 input_fn 中,这是通过调用 tf.contrib.learn.io.numpy_input_fn(...) 在内部完成的。

      更多关于如何构建特征字典的信息可以在Building Input Functions with tf.contrib.learn article of the documentation找到。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-29
        • 1970-01-01
        相关资源
        最近更新 更多