LSTM Keras中的尺寸不匹配 [英] Dimension Mismatch in LSTM Keras
问题描述
我想创建一个可以添加两个字节的基本RNN.这是输入和输出,只需简单的加法即可
I want to create a basic RNN that can add two bytes. Here are the input and outputs, which are expected of a simple addition
X = [[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]]
即X1 = 00101111
和X2 = 01110010
Y = [1, 0, 1, 0, 0, 0, 0, 1]
我创建了以下顺序模型
model = Sequential()
model.add(GRU(output_dim = 16, input_length = 2, input_dim = 8))
model.add(Activation('relu'`))
model.add(Dense(2, activation='softmax'))
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
model.summary()
我遇到的错误是
预计
lstm_input_1
具有3个维度,但数组的形状为(8L, 2L)
expected
lstm_input_1
to have 3 dimensions, but got array with shape(8L, 2L)
因此,如果我通过将X更改为
So if I increase the dimensions by changing X to
[[[0 0]] [[1 1]] [[1 1]] [[1 0]] [[0 0]] [[1 0]] [[0 1]] [[1 0]]]
然后错误更改为
期望
lstm_input_1
具有形状(None, 8, 2)
,但具有形状为(8L, 1L, 2L)
expected
lstm_input_1
to have shape(None, 8, 2)
but got array with shape(8L, 1L, 2L)
推荐答案
将X更改为[[[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]]]
,使其形状为(1, 8, 2)
Change X to [[[0, 0], [0, 1], [1, 1], [0, 1], [1, 0], [1, 0], [1, 1], [1, 0]]]
so that its shape is (1, 8, 2)
这篇关于LSTM Keras中的尺寸不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!