Reputation: 75
I'm new to Tensorflow. I have a image dataset with several labels for one image. As far as I understand, I need to use tf.losses.sigmoid_cross_entropy()
. I tried to apply tf.one_hot
to labels but when I try to pass them into loss function I get error, shapes incompatible. How can I fix this?
Upvotes: 1
Views: 1408
Reputation: 4533
You're right about tf.losses.sigmoid_cross_entropy
. All you need to do is wrap tf.one_hot
with tf.reduce_max
to reduce dimensionality like this.
tf.reduce_max(tf.one_hot(labels, num_classes, dtype=tf.int32), axis=0)
That should return tensor of shape (num_classes,)
, exactly what is needed for your loss function.
Upvotes: 4