Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow: SKCompat Depreciation Warning

NOTE: My first question on here. Pardon for lack of details or info. More than happy to clarify if needed.

I'm running TensorFlow 1.0.0 on Mac and I keep getting this warning when using the learn.Estimator class

WARNING:tensorflow:From :25: calling fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with y is deprecated and will be removed after 2016-12-01. Instructions for updating: Estimator is decoupled from Scikit Learn interface by moving into separate class SKCompat. Arguments x, y and batch_size are only available in the SKCompat class, Estimator will only accept input_fn. Example conversion: est = Estimator(...) -> est = SKCompat(Estimator(...))

I've tried looking this class up and there is zero information in regards to it. Full code is posted here

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

Please let me know if there is any other info that anyone needs

like image 422
Austin Whaley Avatar asked Feb 25 '17 01:02

Austin Whaley


2 Answers

You can import SKCompat from tensorflow.contrib.learn.python:

from tensorflow.contrib.learn.python import SKCompat

And then wrap your estimator with SKCompat() e.g. like this:

classifier = SKCompat(tf.contrib.learn.LinearClassifier(args))
like image 113
acidtobi Avatar answered Sep 28 '22 06:09

acidtobi


Or you simply use the updated Estimator API of TensorFlow r1.1

The API for the model definition is quite similar with some small changes in parameters, return type or function name only. Here is an example that I have used:

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

And you can use this model then like this:

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

An example of an input-function for TensorFlow r1.1 can be found in my answer here.

like image 28
b3nk4n Avatar answered Sep 28 '22 08:09

b3nk4n