开始使用免费开始使用

构建自编码器

自编码器有许多有趣的应用,例如异常检测和图像去噪。它的目标是生成与输入相同的输出。输入会被压缩到更低维的空间,即进行编码。模型随后学习如何将其解码回原始形式。

您将对手写数字的 MNIST 数据集进行编码和解码。隐藏层会将图像编码为 32 维表示,而原图包含 784 个像素(28 x 28)。本质上,自编码器会学习把包含 784 个像素的原始图像压缩成 32 维的表示,并学习如何利用该编码表示重建回原始的 784 个像素图像。

Sequential 模型和 Dense 层已为您准备好。

现在来构建一个自编码器吧!

本练习是课程的一部分

Keras 深度学习入门

查看课程

练习说明

  • 创建一个 Sequential 模型。
  • 添加一个全连接层,其神经元数量与编码后图像的维度一致,input_shape 设为原始图像的像素数。
  • 再添加一个输出层,其神经元数量与输入图像的像素数一致。
  • 使用 adadelta 作为优化器、binary_crossentropy 作为损失函数来编译您的 autoencoder,然后输出模型摘要。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Start with a sequential model
autoencoder = ____

# Add a dense layer with input the original image pixels and neurons the encoded representation
autoencoder.add(____(____, input_shape=(____, ), activation="relu"))

# Add an output layer with as many neurons as the orginal image pixels
autoencoder.add(____(____, activation = "sigmoid"))

# Compile your model with adadelta
autoencoder.compile(optimizer = ____, loss = ____)

# Summarize your model structure
____
编辑并运行代码