【发布时间】:2023-03-05 18:37:01
【问题描述】:
这是模型:
model.add(LSTM(24, input_shape=(120,26), return_sequences = True, activation = 'relu'))
model.add(convolutional.Conv1D(filters = 1, kernel_size=120,activation ='relu'))
model.add(Dense(1))
model.add(Activation('sigmoid'))
opt1 = keras.optimizers.RMSprop(lr=0.0001, rho=0.9, epsilon=1e-08, decay=0.0)
model.compile(loss='binary_crossentropy', optimizer=opt1, metrics=['accuracy'])
filepath="model_check-{epoch:02d}-{loss:.4f}.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='loss', verbose=1,
save_best_only=True, mode='min')
callbacks_list = [checkpoint]
model.fit(df_matrix3, y_matrix3, epochs=2000, batch_size=10000, verbose=2)
以下是输入的尺寸:
df_matrix3 = [0]*10000
df_matrix3t= [0]*10000
for x in range(10000):
df_matrix3[x]=df_matrix[:,0+x:120+x,:]
df_matrix3t[x] = df_matrix[:,1740000+x:1740120+x,:]
df_matrix3 = np.reshape(df_matrix3,(10000,120,26))
y_matrix3 = y[0:10000]
y_matrix3t = y[1740000:1750000]
y_matrix3t = np.reshape(y_matrix3t,(10000,1))
y_matrix3 = np.reshape(y_matrix3,(-1,10000,1))
y_matrix3c = y[1740000:1750000]
这是我得到的错误:
ValueError: 检查目标时出错:预期 activation_15 的形状为 (None, 1, 1) 但得到的数组的形状为 (1, 10000, 1)
这个错误对我来说没有多大意义,因为当我将 LSTM 作为 10,000 个批次单独运行时,它可以正常运行(尽管 return Sequences 设置为 False)。从那以后我所做的就是在第一层添加一个 CNN 层集返回序列 = True,并且输出应该仍然是每个输入的 1 个项目,我希望它是一个 1,10000,1 数组。但是它正在寻找其他东西,我不知道为什么。
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_15 (LSTM) (None, 120, 24) 4896
_________________________________________________________________
conv1d_14 (Conv1D) (None, 1, 1) 2881
_________________________________________________________________
dense_14 (Dense) (None, 1, 1) 2
_________________________________________________________________
activation_14 (Activation) (None, 1, 1) 0
=================================================================
Total params: 7,779
Trainable params: 7,779
这些是我的图层大小,完全符合我的预期。
【问题讨论】:
标签: keras conv-neural-network lstm dimensions