简体   繁体   中英

Error with tf.nn.sparse_softmax_cross_entropy_with_logits

I am using tf.nn.sparse_softmax_cross_entropy_with_logits and when I pass through the labels and logits I get the following error

tensorflow.python.framework.errors_impl.InvalidArgumentError: labels must be 1-D, but got shape [50,1]

I don't understnad how having a shape [50,1] is not the same as being 1D

I don't understand how having a shape [50,1] is not the same as being 1D.

While you can reshape a [50, 1] 2D matrix into a [50] 1D matrix just with a simple squeeze, Tensorflow will never do that automatically.

The only heuristic the tf.nn.sparse_softmax_cross_entropy_with_logits uses to check if the input shape is correct is to check the number of dimensions it has. If it's not 1D, it fails without trying other heuristics like checking if the input could be squeezed. This is a security feature.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM