我想在Keras中實現一個卷積自動編碼器,像下面這樣的圖層。我的數據有1108行和29430列。Keras - 嵌入層的輸入形狀
def build(features, embedding_dims, maxlen, filters, kernel_size):
m = keras.models.Sequential()
m.add(Embedding(features, embedding_dims, input_length=maxlen))
m.add(Dropout(0.2))
m.add(Conv1D(filters, kernel_size, padding='valid', activation='relu', strides=1, input_shape=(len(xx), features)))
m.add(MaxPooling1D())
m.add(Conv1D(filters, kernel_size, padding='valid', activation='relu', strides=1, input_shape=(None, len(xx), features)))
m.add(UpSampling1D())
m.summary()
m.compile(optimizer="adagrad", loss='mse', metrics=['accuracy'])
return m
early = keras.callbacks.EarlyStopping(
monitor='val_loss', patience=10, verbose=1, mode='min')
model = build(len(xx[0]), 60, 11900, 70, 3)
model.fit(xx, xx, batch_size=4000, nb_epoch=10000,validation_split=0.1,
callbacks=[early])
但是,我收到一個錯誤,指出ValueError: Error when checking input: expected embedding_1_input to have shape (None, 11900) but got array with shape (1108, 29430)
。爲什麼第一層期望(無,maxlen)而不是數據的大小?
我還會包括我的模型摘要:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding_1 (Embedding) (None, 11900, 60) 714000
_________________________________________________________________
dropout_1 (Dropout) (None, 11900, 60) 0
_________________________________________________________________
conv1d_1 (Conv1D) (None, 11898, 70) 12670
_________________________________________________________________
max_pooling1d_1 (MaxPooling1 (None, 5949, 70) 0
_________________________________________________________________
conv1d_2 (Conv1D) (None, 5947, 70) 14770
_________________________________________________________________
up_sampling1d_1 (UpSampling1 (None, 11894, 70) 0
=================================================================
Total params: 741,440
Trainable params: 741,440
Non-trainable params: 0
_________________________________________________________________