Keras Flatten不创建1D输出

时间:2019-05-03 09:17:17

标签: python-3.x keras

我正在尝试构建一维CNN,但无法将正确的尺寸传递给我的最后一个密集层

我的模型的架构是

model_CNN=Sequential()
model_CNN.add(Conv1D(14, 29, activation='relu', input_shape=(X_train.shape[1], 1)))    
model_CNN.add(Conv1D(30, 22, activation='relu'))

model_CNN.add(Flatten())

model_CNN.add(Dense(176,activation='relu'))    
model_CNN.add(Dense(Y_train.shape[1],activation='linear'))

摘要如下

Layer (type)                 Output Shape              Param #   
=================================================================
conv1d_71 (Conv1D)           (None, 3304, 14)          420       
_________________________________________________________________
conv1d_72 (Conv1D)           (None, 3283, 30)          9270      
_________________________________________________________________
flatten_18 (Flatten)         (None, 98490)             0         
_________________________________________________________________
dense_102 (Dense)            (None, 176)               17334416  
_________________________________________________________________
dense_103 (Dense)            (None, 5)                 885       
=================================================================
Total params: 17,344,991
Trainable params: 17,344,991
Non-trainable params: 0 

当我尝试拟合模型时,我确认输入形状正确(240、3332、1),但是随后出现以下错误

ValueError: Error when checking target: expected dense_103 
to have 2 dimensions, but got array with shape (240, 5, 1)

所以我的flatten函数不是在创建一维数组,而是以某种方式仅在第二个密集层而不是第一个密集层上输入失败。发生了什么事?

0 个答案:

没有答案