DLS Course 2 week 3 exercise 6, I keep getting the wrong answer

I reshaped Logits and labels on there own lines because it was easier to analyze. I have tried every thing I could by scanning through Forums and I just can’t get it right. I am getting it very close. Where and I miss understadning or typed wrong. Did I get the wrong num_classes. I just don’t know

pred= tf.cast(tf.reshape(logits,[tf.shape(logits)[1],6]), dtype = tf.float32)
true = tf.cast(tf.reshape(labels,[tf.shape(logits)[1],6]), dtype = tf.float32)
cost = tf.reduce_mean(tf.keras.losses.categorical_crossentropy(true,pred, from_logits=True))

Output
tf.Tensor(0.2490923, shape=(), dtype=float32)
Expected output
tf.Tensor(0.4051435, shape=(), dtype=float32)

My recommendation is that you use transpose here. Just because you get the shape the same with “reshape” does not mean that the two operations are equivalent.

Also just on general principles, it’s probably not a good idea to hard-code 6 classes. Not sure whether the grader test cases also have 6 classes.

1 Like