python 降噪
Autoencoders aren’t too useful in practice, but they can be used to denoise images quite successfully just by training the network on noisy images. We can generate noisy images by adding Gaussian noise to the training images, then clipping the values to be between 0 and 1.
自动编码器在实践中并不太有用,但是仅通过在嘈杂的图像上训练网络,它们就可以非常成功地对图像进行去噪。 我们可以通过将高斯噪声添加到训练图像中,然后将值裁剪为0到1之间的方式来生成嘈杂的图像。
“Denoising auto-encoder forces the hidden layer to extract more robust features and restrict it from merely learning the identity. Autoencoder reconstructs the input from a corrupted version of it.”
去噪自动编码器会强制隐藏层提取更强大的功能,并限制其仅学习身份。 自动编码器会从损坏的版本中重建输入。”
A denoising auto-encoder does two things:
去噪自动编码器有两件事:
- Encode the input (preserve the information about the data) 编码输入(保留有关数据的信息)
- Undo the effect of a corruption process stochastically applied to the input of the auto-encoder. 撤消随机应用于自动编码器输入的损坏过程的影响。
For the depiction of the denoising capabilities of Autoencoders, we’ll use noisy images as input and the original, clean images as targets.
为了描述自动编码器的降噪功能,我们将使用嘈杂的图像作为输入,并使用原始的干净图像作为目标。
Example: Top image is input, and the bottom image is the target.
示例:输入了顶部图像,而底部图像是目标。
问题陈述: (Problem Statement:)
Build the model for the denoising autoencoder. Add deeper and additional layers to the network. Using MNIST dataset, add noise to the data and try to define and train an autoencoder to denoise the images.
为降噪自动编码器构建模型。 向网络添加更深的层。 使用MNIST数据集,向数据添加噪声,并尝试定义和训练自动编码器以对图像进行降噪。
解: (Solution:)
Import Libraries and Load Dataset: Given below is the standard procedure to import the libraries and load the MNIST dataset.
导入库和加载数据集:以下是导入库和加载MNIST数据集的标准过程。
import torch
import numpy as np
from torchvision import datasets
import torchvision.transforms as transforms# convert