用于keras中文本的Conv1D卷积自动编码器

时间:2018-03-29 09:36:24

标签: keras convolution keras-layer autoencoder keras-2

我如何解决这个问题

ValueError:检查目标时出错:预期conv-decode3具有形状(无,14,300)但是具有形状的数组(6559,16,300)

NUM_WORDS = 3
pool_size = 2
x = Input(shape=(16, 300), name="input")
h = x
h = Conv1D(filters=300, kernel_size=NUM_WORDS,
             activation="relu", padding='same', name='Conv1')(h)
h = MaxPooling1D(pool_size=pool_size, name='Maxpool1')(h)
h = Conv1D(filters=150, kernel_size=NUM_WORDS,
             activation="relu", padding='same', name='Conv2')(h)
h = MaxPooling1D(pool_size=pool_size,  name="Maxpool2")(h)
h = Flatten() (h)
h = Dense(10, name='embedding') (h)
y = h
y = Dense(600, activation="relu") (y)
y = Reshape((4, 150)) (y)
y = Conv1D(filters=150, kernel_size=NUM_WORDS,
             activation="relu", padding='same', name='conv-decode1')(y)
y = UpSampling1D(size=pool_size, name='upsampling1')(y)
y = Conv1D(filters=300, kernel_size=NUM_WORDS,
             activation="relu", padding='same', name='conv-decode2')(y)
y = UpSampling1D(size=pool_size, name='upsampling2')(y)


return Model(inputs=x, outputs=y, name='AE'), Model(inputs=x, outputs=h, name='encoder')

1 个答案:

答案 0 :(得分:1)

你还有这个问题吗?您的1D AE不包含图层的定义:conv-decode3

我刚刚添加了编辑并打印了模型 - 看起来不错 - 输入形状等于输出形状。 扬

y = UpSampling1D(size=pool_size, name='upsampling2')(y)

autoencoderM = Model(x, y)
myLoss='mean_squared_error'
autoencoderM.compile(optimizer='adadelta', loss=myLoss)

autoencoderM.summary() # will print

图层(类型)输出形状参数#

输入(InputLayer)(无,16,300)0

Conv1(Conv1D)(无,16,300)270300

。 。

conv-decode2(Conv1D)(无,8,300)135300

upsampling2(UpSampling1D)(无,16,300)0

总参数:621,010