autoencoder.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:dsde-deep-learning 作者: broadinstitute 项目源码 文件源码
def build_simple_autoencoder(input_dim=784, encoding_dim=32, l1_penalty=0.):
    # this is the size of our encoded representations
    # 32 floats -> compression of factor 24.5, assuming the input is 784 floats
    # this is our input placeholder
    input_img = Input(shape=(input_dim,))

    # "encoded" is the encoded representation of the input
    encoded = Dense(encoding_dim, activation='relu',  activity_regularizer=regularizers.l1(l1_penalty))(input_img)

    # "decoded" is the lossy reconstruction of the input
    decoded = Dense(input_dim, activation='sigmoid')(encoded)

    # this model maps an input to its reconstruction
    autoencoder = Model(input_img, decoded)

    # this model maps an input to its encoded representation
    encoder = Model(input_img, 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(encoded_input, decoder_layer(encoded_input))

    autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
    return encoder, decoder, autoencoder
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号