keras 中文本的 Conv1D 卷积自动编码器
Conv1D convolutional Autoencoder for text in keras
我是如何解决这个问题的
ValueError:检查目标时出错:预期 conv-decode3 的形状为 (None, 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')
你还有这个问题吗?您的 1D AE 不包含 layer: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) (None, 16, 300) 0
Conv1 (Conv1D) (None, 16, 300) 270300
。 . .
conv-decode2 (Conv1D) (None, 8, 300) 135300
上采样 2 (UpSampling1D) (None, 16, 300) 0
总参数:621,010
我是如何解决这个问题的
ValueError:检查目标时出错:预期 conv-decode3 的形状为 (None, 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')
你还有这个问题吗?您的 1D AE 不包含 layer: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) (None, 16, 300) 0
Conv1 (Conv1D) (None, 16, 300) 270300
。 . .
conv-decode2 (Conv1D) (None, 8, 300) 135300
上采样 2 (UpSampling1D) (None, 16, 300) 0
总参数:621,010