Denoising Autoencoders are neural network models that remove noise from corrupted or noisy data by learning to reconstruct the initial data from its noisy counterpart. We train the model to minimize the disparity between the original and reconstructed data. We can stack these autoencoders together to form deep networks, increasing their performance.
Additionally, tailor this architecture to handle a variety of data formats, including images, audio, and text. Additionally, customise the noise, such as including salt-and-pepper or Gaussian noise. As the DAE reconstructs the image, it effectively learns the input features, leading to enhanced extraction of latent representations. It is important to highlight that the Denoising Autoencoder reduces the likelihood of learning the identity function compared to a regular autoencoder.
This article was published as a part of the Data Science Blogathon.
Denoising autoencoders are a specific type of neural network that enables unsupervised learning of data representations or encodings. Their primary objective is to reconstruct the original version of the input signal corrupted by noise. This capability proves valuable in problems such as image recognition or fraud detection, where the goal is to recover the original signal from its noisy form.
An autoencoder consists of two main components:
During the training phase, present the autoencoder with a set of clean input examples along with their corresponding noisy versions. The objective is to learn a task using an encoder-decoder architecture that efficiently transforms noisy input into clean output.
The denoising autoencoder (DAE) architecture is similar to a standard autoencoder. It consists of two main components:
During the training phase, present the denoising autoencoder (DAE) with a collection of clean input examples along with their respective noisy counterparts. The objective is to acquire a function that maps a noisy input to a relatively clean output using an encoder-decoder architecture. To achieve this, a reconstruction loss function is typically employed to evaluate the disparity between the clean input and the reconstructed output. A DAE is trained by minimizing this loss through the use of backpropagation, which involves updating the weights of both encoder and decoder components.
Applications of Denoising Autoencoders (DAEs) span a variety of domains, including computer vision, speech processing, and natural language processing.
Denoising autoencoders (DAEs) provide a powerful solution for reconstructing the original data from its noisy version. In particular, when it comes to image denoising, DAE can be extremely effective. By providing a noisy image as input, DAE creates a reconstructed version of the original image. The training process involves minimizing the discrepancy between the original and reconstructed images. Once the DAE has completed its training, it can be employed to denoise new images by removing unwanted noise and reconstructing the original image.
To illustrate this, let’s consider an example using the Keras digit MNIST dataset. This dataset consists of 60,000 28×28 grayscale images (0-9) of handwritten digits for training and an additional 10,000 images for testing. We can use a denoising autoencoder to denoise these images.
To begin, make sure you have the required libraries installed and load the dataset.
# Installing libraries
!pip install tensorflow numpy matplotlib
# Loading dataset
from tensorflow.keras.datasets import mnist
(x_train, _), (x_test, _) = mnist.load_data()
# Add noise to the images
noise_factor = 0.5
x_train_noisy = x_train + noise_factor * np.random.normal(loc=0.0, scale=1.0, size=x_train.shape)
x_test_noisy = x_test + noise_factor * np.random.normal(loc=0.0, scale=1.0, size=x_test.shape)
# Clip the images to the valid pixel range
x_train_noisy = np.clip(x_train_noisy, 0., 1.)
x_test_noisy = np.clip(x_test_noisy, 0., 1.)
# Normalize the pixel values
x_train_noisy = x_train_noisy / 255.
x_test_noisy = x_test_noisy / 255.
Afterwards, you can proceed to define the denoising autoencoder model utilizing the Keras functional API.
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D
from tensorflow.keras.models import Model
# Define the input layer
input_layer = Input(shape=(28, 28, 1))
# Encoder
x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_layer)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
# Decoder
x = Conv2D(32, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
# Define the model
autoencoder = Model(input_layer, decoded)
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
Lastly, you can train the model and utilize it to denoise the images.
# Train the model
autoencoder.fit(x_train_noisy, x_train, epochs=10, batch_size=128,
validation_data=(x_test_noisy, x_test))
# Using model to denoise the images
denoised_images = autoencoder.predict(x_test_noisy)
To visualize the original, noisy, and denoised images, you can utilize the Matplotlib library.
import matplotlib.pyplot as plt
# Display the first image in the test set
plt.imshow(x_test[0], cmap='gray')
plt.show()
# Display the first image in the noisy test set
plt.imshow(x_test_noisy[0], cmap='gray')
plt.show()
# Display the first image in the denoised test set
plt.imshow(denoised_images[4].squeeze(), cmap='gray')
plt.show()
Output:
In the provided output, the images are organized as follows:
Notice how the reconstructed images closely resemble the original ones.
However, upon closer inspection, you may notice that the updated image looks a bit blurry. There are several possible reasons for this confusion in the decoder network output. One of the reasons for this is the use of less time during the study period. Therefore, your task is to increase the number of periods and re-evaluate the resulting image. Compare the increase in the number of results obtained with the previous period.
Denoising autoencoders (DAEs) offer several advantages over traditional noise reduction techniques. They effectively avoid the problem of creating oversimplified images, and they compute quickly. Unlike traditional filtering methods, DAEs use an improved autoencoder approach that involves inserting noise into the input and reconstructing the output from the corrupted image.
This modification to the standard autoencoder approach prevents the DAE from copying input to output. Instead, DAEs need to remove noise from the input before extracting meaningful information.
In our specific DAE approach, we have used CNN due to its effectiveness in deducing and preserving spatial relationships within an image. Additionally, employing CNNs helps reduce dimensions and computational complexity, making it possible to use arbitrary-sized images as input.
A. An autoencoder is a type of artificial neural network (ANN) that operates as an unsupervised machine learning algorithm. It utilizes backpropagation and sets the target values equal to the input values during training. The primary objective of an autoencoder is to encode and decode data to reconstruct the original input.
A. Autoencoders function using the following components to accomplish the mentioned tasks:
1. Encoder: The encoder layer converts the input image into a compressed image with a reduced size. This compressed image is a distorted version of the original image.
2. Code: This part of the network represents the compressed input to the decoders.
3. Decoder: The decoder layer restores the encoded image to its original dimensions in a lossy manner. reconstruction process by revealing the hidden space.
A. Autoencoders have various applications in the field of image processing and analysis. Some of their uses include:
Dimensionality Reduction: Autoencoders can effectively reduce the dimensionality of image data while preserving essential information and features. Image denoising: Autoencoders can be used to remove noise from an image, increasing its quality and clarity. Feature extraction: Autoencoders are able to learn and extract meaningful features. from images, aiding in further analysis or classification tasks.
Data compression: Autoencoders can compress image data by learning a compact representation, enabling efficient storage and transmission. Removing watermarks from images: Autoencoder can be used to remove unwanted watermarks or artifacts from images, reconstructing.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.