Getting Error on Cost Function But i don’t understand y Please help…
Hi Akib, welcome to the community!
It’s important to note that the “y_pred” and “y_true” inputs of tf.keras.losses.categorical_crossentropy are expected to be of shape (num_examples, num_classes). Since the “y_pred” vector (logits) has the shape (6, num_examples) and you’re using categorical cross-entropy, TensorFlow’s loss function expects the shape (num_examples, num_classes) by default.
Since the logits shape is (6, num_examples), this indicates that 6 is the number of labels (num_classes) and num_examples is the batch size. This means you must transpose the logits to match the expected shape for the cross-entropy function. Similarly, the labels vector (“y_true”) should be transposed to match (num_examples, num_classes):
tf.keras.losses.categorical_crossentropy(tf.transpose(labels), tf.transpose(logits), from_logits=True)
I hope this solves your problem!

