且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

(使用Keras)的Tensorflow中``InvalidArgumentError:形状不兼容:[10,2] vs. [10]''的原因是什么?

更新时间:2023-12-02 08:33:10

to_categorical通常在具有列表格式标签且需要执行one-hot编码以将其转换为正确形状时使用在训练期间将其输入模型.

to_categorical is usually used when you have the label in the list format and you need to perform one-hot encoding in order to transform it to the correct shape to feed it to models during training.

但是在您的情况下,标签的形状已经与模型中定义的形状相同,因此不需要one-hot编码.

But in your case, your label is already of the same shape as you defined in your model, so the one-hot encoding is not necessary.

您可以将None视作batch_size,这将使您更清楚地了解数据是如何从输入转换为输出的.

You can view the None as batch_size and this will give you a clearer picture of how the data are transformed from the input to the output.

谢谢!