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

本秂侑毒 提交于 2019-12-01 10:53:33
Ismael

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.

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!