首页 文章

关于Keras框架下自动编码器模型中的解码器层定义

提问于
浏览
4

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))

1 回答

  • 0

    encoded_input 表示占位符,如果您只想运行解码器而不是编码器来生成某些数据(例如,如果您正在探索编码空间),则可以使用占位符 .

相关问题