大家好,我必须实现一个cnn + lstm模型,我发现了这个错误:
ValueError: Error when checking target: expected dense_17 to have shape (None, 1) but got array with shape (8, 4800000)
这是我的代码:
X_train.shape = (8, 4800000, 1)
y_train_arousal.shape=(8, 4800000).
X_train是8个音轨,4800000是样本,1个频道
y_train_arousal:对于每个音轨,每个样本对应一个唤醒值。
所以我的模型按顺序读取样本并且每个样本产生1个值,我必须评估输出值与样本之间的差异
model_arousal = Sequential()
model_arousal.add(Conv1D(filters=40, kernel_size=40, strides=2, activation='tanh', input_shape=(4800000, 1)))
model_arousal.add(MaxPooling1D(pool_size=2))
model_arousal.add(Dropout(0.5))
model_arousal.add(Conv1D(filters=40, kernel_size=400, strides=2, activation='tanh'))
model_arousal.add(MaxPooling1D(pool_size=20))
model_arousal.add(Dropout(0.5))
model_arousal.add(LSTM(128, activation='tanh', return_sequences=True))
model_arousal.add(LSTM(128, activation='tanh', return_sequences=True))
model_arousal.add(Flatten())
model_arousal.add(Dense(2))
adam = Adam(0.002)
model_arousal.compile(loss='mse', optimizer=adam, metrics=['accuracy'])
model_arousal.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_47 (Conv1D) (None, 2399981, 40) 1640
_________________________________________________________________
max_pooling1d_42 (MaxPooling (None, 1199990, 40) 0
_________________________________________________________________
dropout_39 (Dropout) (None, 1199990, 40) 0
_________________________________________________________________
conv1d_48 (Conv1D) (None, 599796, 40) 640040
_________________________________________________________________
max_pooling1d_43 (MaxPooling (None, 29989, 40) 0
_________________________________________________________________
dropout_40 (Dropout) (None, 29989, 40) 0
_________________________________________________________________
lstm_19 (LSTM) (None, 29989, 128) 86528
_________________________________________________________________
lstm_20 (LSTM) (None, 29989, 128) 131584
_________________________________________________________________
flatten_19 (Flatten) (None, 3838592) 0
_________________________________________________________________
dense_17 (Dense) (None, 1) 3838593
=================================================================
Total params: 4,698,385
Trainable params: 4,698,385
Non-trainable params: 0
_________________________________________________________________
h = model_arousal.fit(X_train, y_train_arousal, batch_size=50, epochs=5, verbose=1)
更新
我试图尽可能清楚地解释自己。
为简单起见,我只考虑一个音轨。对于轨道的每个样本对应一个唤醒值。 所以我的网络必须为每个样本预测一个唤醒值,然后将它与样本的相应唤醒值进行比较