【问题标题】:TensorFlow: SKCompat Depreciation WarningTensorFlow:兼容弃用警告
【发布时间】:2017-07-16 00:27:04
【问题描述】:

注意:我在这里的第一个问题。请原谅缺乏细节或信息。如果需要,非常乐意澄清。

我在 Mac 上运行 TensorFlow 1.0.0,并且在使用 learn.Estimator 类时不断收到此警告

警告:张量流:从 :25:调用 适合(来自 tensorflow.contrib.learn.python.learn.estimators.estimator) with y 已弃用,并将在 2016-12-01 之后删除。 更新说明:Estimator 与 Scikit Learn 解耦 通过移动到单独的类 SKCompat 来进行接口。参数 x、y 和 batch_size 仅在 SKCompat 类中可用,Estimator 将 只接受 input_fn。转换示例:est = Estimator(...) -> est = SKCompat(Estimator(...))

我已尝试查找该课程,但关于它的信息为零。完整代码贴在这里

https://github.com/austinmwhaley/DeepFarm/blob/master/prototype_1.ipynb

如果有人需要任何其他信息,请告诉我

【问题讨论】:

  • 我在关注cnn_mnist tutorial 时遇到了类似的问题。根据错误信息,我尝试了类似from tensorflow.contrib.learn.SKCompat import SKCompat 的方法,然后他们用SKCompat() 包装了Estimator。但它不起作用...错误:“没有名为 SKCompat 的模块”。也需要一些帮助!

标签: python machine-learning tensorflow


【解决方案1】:

您可以从 tensorflow.contrib.learn.python 导入 SKCompat:

from tensorflow.contrib.learn.python import SKCompat

然后用 SKCompat() 包装您的估算器,例如像这样:

classifier = SKCompat(tf.contrib.learn.LinearClassifier(args))

【讨论】:

    【解决方案2】:

    或者您只需使用updated Estimator API of TensorFlow r1.1

    模型定义的 API 非常相似,只是在参数、返回类型或函数名称上做了一些小改动。这是我用过的一个例子:

    def model_fn():
        def _build_model(features, labels, mode, params):
            # 1. Configure the model via TensorFlow operations
            # Connect the first hidden layer to input layer (features) with relu activation
            y = tf.contrib.layers.fully_connected(features, num_outputs=64, activation_fn=tf.nn.relu,
                                                  weights_initializer=tf.contrib.layers.xavier_initializer())
            y = tf.contrib.layers.fully_connected(y, num_outputs=64, activation_fn=tf.nn.relu,
                                                  weights_initializer=tf.contrib.layers.xavier_initializer())
            y = tf.contrib.layers.fully_connected(y, num_outputs=1, activation_fn=tf.nn.sigmoid,
                                                  weights_initializer=tf.contrib.layers.xavier_initializer())
    
            predictions = y
    
            # 2. Define the loss function for training/evaluation
            if mode == tf.estimator.ModeKeys.TRAIN or mode == tf.estimator.ModeKeys.EVAL:
                loss = tf.reduce_mean((predictions - labels) ** 2)
            else:
                loss = None
    
            if mode != tf.estimator.ModeKeys.PREDICT:
                eval_metric_ops = {
                    "rmse": tf.metrics.root_mean_squared_error(tf.cast(labels, tf.float32), predictions),
                    "accuracy": tf.metrics.accuracy(tf.cast(labels, tf.float32), predictions),
                    "precision": tf.metrics.precision(tf.cast(labels, tf.float32), predictions)
                }
            else:
                eval_metric_ops = None
    
            # 3. Define the training operation/optimizer
            if mode == tf.estimator.ModeKeys.TRAIN:
                train_op = tf.contrib.layers.optimize_loss(
                    loss=loss,
                    global_step=tf.contrib.framework.get_global_step(),
                    learning_rate=0.001,
                    optimizer="Adam")
            else:
                train_op = None
    
            if mode == tf.estimator.ModeKeys.PREDICT:
                predictions_dict = {"pred": predictions}
            else:
                predictions_dict = None
    
            # 5. Return predictions/loss/train_op/eval_metric_ops in ModelFnOps object
            return tf.estimator.EstimatorSpec(mode=mode,
                                              predictions=predictions_dict,
                                              loss=loss,
                                              train_op=train_op,
                                              eval_metric_ops=eval_metric_ops)
        return _build_model
    

    然后你可以像这样使用这个模型:

    e = tf.estimator.Estimator(model_fn=model_fn(), params=None)
    e.train(input_fn=input_fn(), steps=1000)
    

    TensorFlow r1.1 的输入函数示例可以在我的回答 here 中找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-11
      • 2021-07-12
      • 2017-08-22
      相关资源
      最近更新 更多