且构网

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

keras,带有RNN模型的MNIST分类,关于输出形状的问题

更新时间:2023-12-02 08:02:40

您的数据(目标)的形状为(60000, 10).

You data (targets) has shape (60000, 10).

您模型的输出(密集")的形状为(None, length, 10).

Your model's output ('dense') has shape (None, length, 10).

其中None是批次大小(变量),length是中间尺寸,表示LSTM的时间步长",而10是Dense层的单位.

Where None is the batch size (variable), length is the middle dimension, which mean "time steps" for an LSTM, and 10 is the units of the Dense layer.

现在,您没有在LSTM中处理时间序列的任何顺序,这没有任何意义.它将图像行"解释为连续的时间步长,将图像列"解释为独立的特征. (如果这不是您的意图,那么您就很幸运,它没有给您尝试将图像放入LSTM的错误)

Now, you don't have any sequence with time steps to process in an LSTM, it doesn't make sense. It is interpreting "image rows" as sequential time steps and "image columns" as independent features. (If this was not your intention, you simply got lucky that it didn't give you an error for trying to put an image into an LSTM)

无论如何,您可以使用return_sequences=False修复此错误(丢弃序列的length).这并不意味着该模型对于这种情况是***的.

Anyway, you can fix this error with return_sequences=False (discard the length of the sequences). Which does not mean this model is optimal for this case.