我的自动编码器输入向量大小为 128。我总共有 730 个样本 (730x128(。我正在尝试使用1D CNN自动编码器。我想稍后使用隐藏层作为我新的低维表示形式。我的代码现在正在运行,但我解码的输出甚至不接近原始输入。这是代码:
input_sig = Input(batch_shape=(None,128,1))
x = Conv1D(64,3, activation='relu', padding='valid')(input_sig)
x1 = MaxPooling1D(2)(x)
x2 = Conv1D(32,3, activation='relu', padding='valid')(x1)
x3 = MaxPooling1D(2)(x2)
flat = Flatten()(x3)
encoded = Dense(32,activation = 'relu')(flat)
print("shape of encoded {}".format(K.int_shape(flat)))
x2_ = Conv1D(32, 3, activation='relu', padding='valid')(x3)
x1_ = UpSampling1D(2)(x2_)
x_ = Conv1D(64, 3, activation='relu', padding='valid')(x1_)
upsamp = UpSampling1D(2)(x_)
flat = Flatten()(upsamp)
decoded = Dense(128,activation = 'relu')(flat)
decoded = Reshape((128,1))(decoded)
print("shape of decoded {}".format(K.int_shape(x1_)))
autoencoder = Model(input_sig, decoded)
autoencoder.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
然后自动编码器的输入为 --> (730,128,1(但是当我根据解码绘制原始信号时,它们非常不同!!感谢您对此的帮助。
您需要具有"sigmoid"激活的单通道卷积层来重建解码的图像。请看下面的例子。你可以用 loss='mse' 和 optimizer='adam' 编译它
input_sig = Input(batch_shape=(1,128,1))
x = Conv1D(8,3, activation='relu', padding='same',dilation_rate=2)(input_sig)
x1 = MaxPooling1D(2)(x)
x2 = Conv1D(4,3, activation='relu', padding='same',dilation_rate=2)(x1)
x3 = MaxPooling1D(2)(x2)
x4 = AveragePooling1D()(x3)
flat = Flatten()(x4)
encoded = Dense(2)(flat)
d1 = Dense(64)(encoded)
d2 = Reshape((16,4))(d1)
d3 = Conv1D(4,1,strides=1, activation='relu', padding='same')(d2)
d4 = UpSampling1D(2)(d3)
d5 = Conv1D(8,1,strides=1, activation='relu', padding='same')(d4)
d6 = UpSampling1D(2)(d5)
d7 = UpSampling1D(2)(d6)
decoded = Conv1D(1,1,strides=1, activation='sigmoid', padding='same')(d7)
model= Model(input_sig, decoded)