TensorFlowDNNClassifier class is deprecated but replacement does not seem to work?

前端 未结 2 784
北恋
北恋 2021-01-15 10:30

Using the following with TF .9.0rc0 on 60,000 (train) and 26,000 (test) on or so records with 145 coded columns (1,0) trying to predict 1 or 0 for class identification..

相关标签:
2条回答
  • 2021-01-15 10:37

    I don't think it is a bug, from the source code of DNNClassifier, I can tell that its usage differs from TensorFlowDNNClassifier. The constructor of DNNClassifier doesn't have the steps param:

    def __init__(self,
               hidden_units,
               feature_columns=None,
               model_dir=None,
               n_classes=2,
               weight_column_name=None,
               optimizer=None,
               activation_fn=nn.relu,
               dropout=None,
               config=None)
    

    As you could see here. Instead the fit() method that DNNClassifier inherited from BaseEstimator now has the steps param, notice that the same happens with batch_size:

      def fit(self, x=None, y=None, input_fn=None, steps=None, batch_size=None,
              monitors=None):
    

    For the "it hangs with no completion?", in the doc of the fit() method of BaseEstimator it is explained that if steps is None (as the value by default), the model will train forever.

    I still don't get why I would like to train a model forever. My guesses are that creators think this way is better for the classifier if we want to have early stopping on validation data, but as I said is only my guess.

    As you could see DNNClassifier doesn't give any feedback as the deprecated TensorFlowDNNClassifier, it is supposed that the feedback can be setup with the 'config' param that is present in the constructor of DNNClassifier. So you should pass a RunConfig object as config, and in the params of this object you should set the verbose param, unfortunately I tried to set it so I can see the progress of the loss, but didn't get so lucky.

    I recommend you to take a look at the latest post of Yuan Tang in his blog here, one of the creators of the skflow, aka tf learn.

    0 讨论(0)
  • 2021-01-15 10:56

    I just had a similar issue @Ismael answer is correct. I just wanted to add to the information that now classifier.fit() has the steps parameter that this parameter behaves differently. It doesn't abort earlier. There is another parameter called max_steps. That behaves as the original steps parameter of TensorFlowDNNClassifier.

    In short just use the max_steps parameter on fit() like this:

    classifier = skflow.DNNClassifier(...)
    classifier.fit(X_train, y_train, max_steps=3000)
    
    0 讨论(0)
提交回复
热议问题