`logits` and `labels` must have the same shape, received ((None, 10) vs (None, 1)).
时间: 2024-01-25 22:05:17 浏览: 131
Standardized Max Logits.pdf
The error message you mentioned usually occurs when the shapes of the `logits` and `labels` do not match. In your case, the shape of `logits` is (None, 10), while the shape of `labels` is (None, 1). To resolve this issue, you need to ensure that the shapes of `logits` and `labels` are identical.
You can try reshaping the `labels` tensor to match the shape of `logits`. For example, if you want to reshape `labels` from (None, 1) to (None, 10), you can use the `tf.keras.backend.repeat_elements` function. Here's an example:
```
import tensorflow as tf
# Assuming logits has shape (None, 10)
logits = ... # Your logits tensor
labels = ... # Your labels tensor with shape (None, 1)
# Reshape labels to match the shape of logits
labels = tf.keras.backend.repeat_elements(labels, rep=10, axis=1)
# Now logits and labels have the same shape
```
Make sure to adjust the axis argument in `repeat_elements` based on your specific use case.
阅读全文