每个循环层都需要输出,我的设置如下:
100个训练示例,每个示例3个时间步,每个元素20d特征向量。
x_train:(100,3,20)
y_train:(100,20)
LSTM体系结构:
model.add(LSTM(20, input_shape=(3,20), return_sequences=True))
model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['accuracy'])
model.summary()
培训:
history = model.fit(x_train, y_train, epochs=50, validation_data=(x_test, y_test))
错误:
ValueError: Dimensions must be equal, but are 20 and 3 for '{{node Equal}} = Equal[T=DT_FLOAT, incompatible_shape_error=true](IteratorGetNext:1, Cast_1)' with input shapes: [?,20], [?,3].
请为我提供正确的输入/输出LSTM尺寸。 谢谢
答案 0 :(得分:0)
LSTM(20, input_shape=(3,20), return_sequences=True)
作为输入形状(100,3,20)
并返回(100,3,20)
。但是,您的目标输出被编码为(100,20)
。
从维度上看,我假设您想将每个序列映射到非序列,即可以:
LSTM(20, input_shape=(3,20), return_sequences=False)
这将返回最终的隐藏状态,即(100,20)
的形状与您的目标输出相匹配。