dward4
dward4

Reputation: 1922

Tensorflow ValueError: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)

Above error arises from traditional code

tf.nn.sigmoid_cross_entropy_with_logits(self.D_logits_, tf.ones_like(self.D_))

And occurs using Tensorflow V1.0 or greater.

The code itself seems error free, how is this fixed?

Upvotes: 2

Views: 1610

Answers (1)

dward4
dward4

Reputation: 1922

The error itself gives you the fix, you now need to explicitly state which represents the logits and which represents the labels, Tensorflow will no longer assume for you.

This has occured likely because you're working off of outdated code that was written to function before Tensorflow 1.0.

Instead of:

(self.D_logits_, tf.ones_like(self.D_))

We want:

(logits=self.D_logits_, labels=tf.ones_like(self.D_))

Updated code:

tf.nn.sigmoid_cross_entropy_with_logits(logits=self.D_logits_, labels=tf.ones_like(self.D_))

Thanks to @Mrry who suggested the solution originally here: https://github.com/tensorflow/tensorflow/issues/7814

Upvotes: 3

Related Questions