ValueError: `logits` and `labels` must have the same shape, received ((None, 3) vs (None, 1)).
时间: 2024-01-27 21:03:28 浏览: 98
python3.7解决最小二乘遇到ValueError:Expected 2D array, got 1D array instead: array=[5.].关于reshape和predict
This error occurs when the shapes of the `logits` and `labels` tensors do not match. In this case, the `logits` tensor has shape `(None, 3)` while the `labels` tensor has shape `(None, 1)`.
To fix this error, you need to ensure that the shapes of the `logits` and `labels` tensors match. This may involve adjusting the architecture of your neural network, reshaping the input data, or adjusting the loss function.
If you are using a multi-class classification task with `n` classes, you need to ensure that the output layer of your neural network has `n` units and that the `labels` tensor is one-hot encoded with shape `(None, n)`.
If you are using a binary classification task, you need to ensure that the output layer of your neural network has a single unit and that the `labels` tensor is not one-hot encoded and has shape `(None, 1)`.
In either case, you may need to adjust the loss function to match the problem you are solving. For example, if you are solving a binary classification problem, you may want to use the binary cross-entropy loss function, while for a multi-class classification problem, you may want to use the categorical cross-entropy loss function.
阅读全文