【发布时间】:2017-04-18 02:11:30
【问题描述】:
在this blog中包含的自动编码器示例中,作者构建一个隐藏层如下。
# this is the size of our encoded representations
encoding_dim = 32 # 32 floats -> compression of factor 24.5, assuming the input is 784 floats
input_img = Input(shape=(784,))
encoded = Dense(encoding_dim, activation='relu')(input_img)
decoded = Dense(784, activation='sigmoid')(encoded)
autoencoder = Model(input=input_img, output=decoded)
# this model maps an input to its encoded representation
encoder = Model(input=input_img, output=encoded)
我可以理解上面的部分是如何工作的,但是我对下面构建解码器部分的部分感到困惑
# create a placeholder for an encoded (32-dimensional) input
encoded_input = Input(shape=(encoding_dim,))
# retrieve the last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# create the decoder model
decoder = Model(input=encoded_input, output=decoder_layer(encoded_input))
具体来说,我认为decoder 应该定义为decoder = Model(input=encoded, output=decoded)。我不明白为什么我们必须引入额外的变量encoded_input。根据自动编码器模型,我们只是将编码部分解码为输出,因此解码器层的输入应该是encoded。
而且,如果解码器模型定义如上,为什么编码器没有定义为encoder=Model(input=input_img, output=autoencoder.layers[0](input_img))?
【问题讨论】:
标签: tensorflow deep-learning theano keras keras-layer