Keras Autoeoncoder如何解卷积编码器输出以匹配输入图像

时间:2019-02-27 18:40:51

标签: python tensorflow keras conv-neural-network autoencoder

我正在尝试构建一种自动编码器,以重建尺寸为 30 x 24 的图像。我想对编码结果进行聚类,以识别数据中的任何非直观模式。

列代表每小时,行代表不同的操作。由于行未链接,因此我想构建将尺寸减小到1的内核,因此引入了stride = [30,1] 。在conv2d中,我可以将尺寸减小为 1 x 24 x 16 ,但没有找到通过角膜进行反卷积以重建图像的方法,因此我可以训练模型。您知道如何从 1x24x16 的upsampling2d输出中重新创建尺寸为 30x24x1 的图像吗?

from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D, Flatten
from keras.models import Model
from keras import backend as K

input_img = Input(shape=(30, 24, 1))  # adapt this if using `channels_first` image data format
x_train = np.reshape(x_train, (train_size, 30, 24, 1))  # adapt this if using `channels_first` image data format
x_test = np.reshape(x_test, (test_size, 30, 24, 1))  # adapt this if using `channels_first` image data format

x = Conv2D(16, kernel_size= (30, 3), activation='relu', padding='same', strides = (30,1))(input_img)
encoded = MaxPooling2D((1, 2), padding='same')(x)

x = UpSampling2D((1, 2))(encoded)
decoded = Conv2D(1,  kernel_size=(30, 24), activation='sigmoid', padding='same', strides = (30,1))(x)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

Autoencoder.summary()

Layer (type)                 Output Shape              Param #   
=================================================================
input_11 (InputLayer)        (None, 30, 24, 1)         0         
_________________________________________________________________
conv2d_17 (Conv2D)           (None, 1, 24, 16)         1456      
_________________________________________________________________
max_pooling2d_9 (MaxPooling2 (None, 1, 12, 16)         0         
_________________________________________________________________
up_sampling2d_9 (UpSampling2 (None, 1, 24, 16)         0         
_________________________________________________________________
conv2d_18 (Conv2D)           (None, 1, 24, 1)          11521     
=================================================================
Total params: 12,977
Trainable params: 12,977
Non-trainable params: 0

0 个答案:

没有答案