TensorFlow estimator number of classes does not change

筅森魡賤 提交于 2019-12-05 18:50:41

That's a good question. tf.estimator.DNNClassifier is using tf.losses.sparse_softmax_cross_entropy loss, in other words it expects ordinal encoding, instead of one-hot (can't find it in the doc, only the source code):

labels must be a dense Tensor with shape matching logits, namely [D0, D1, ... DN, 1]. If label_vocabulary given, labels must be a string Tensor with values from the vocabulary. If label_vocabulary is not given, labels must be an integer Tensor with values specifying the class index.

You should read the data with one_hot=False and also cast the labels to int32 to make it work:

y=ydata.astype(np.int32)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!