【发布时间】:2021-12-04 17:46:18
【问题描述】:
我正在使用 LSTM 架构处理多分类问题。它似乎有一个不兼容的形状错误。请帮我调试模型。提前致谢。
这里我提供了模型:
# build the network
model = Sequential()
model=models.Sequential()
model.add(layers.LSTM(1024,activation='tanh',input_shape=x_train.shape[1:], return_sequences=True))
model.add(layers.LSTM(512,activation='tanh',return_sequences=True))
model.add(layers.Flatten())
model.add(layers.Dense(3,activation='sigmoid'))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()
这是这个 LSTM 模型的总结:
finished loading 7740 subjects from 3 classes
train / test split: 6192, 1548
training data shape: (6192, 16000, 1)
training labels shape: (6192, 3)
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm (LSTM) (None, 16000, 1024) 4202496
_________________________________________________________________
lstm_1 (LSTM) (None, 16000, 512) 3147776
_________________________________________________________________
flatten (Flatten) (None, 8192000) 0
_________________________________________________________________
dense (Dense) (None, 3) 24576003
=================================================================
Total params: 31,926,275
Trainable params: 31,926,275
Non-trainable params: 0
这是训练/拟合:
results = model.fit(x_train, y_train, epochs = 500, batch_size=16,validation_data= (x_test, y_test))
我得到的错误:
ValueError: Input 0 of layer lstm is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 800, 20, 1)
【问题讨论】:
-
请避免使用粗体,重点除外(已编辑)。
标签: python deep-learning conv-neural-network lstm multiclass-classification