Heavy computation is a well known drawback in varied ML algorithms in the present day, particularly when generative AI is utilized to textual content, pictures, and different unstructured information.
One of many principal approaches to mitigate this drawback is to compress enter information right into a lower-dimensional illustration whereas preserving the principle context. There are numerous strategies that obtain this objective, together with autoencoders, which we are going to talk about on this article.
For simplicity, on this article, we are going to concentrate on image-based autoencoders, however keep in mind, they are often utilized to different information sorts as properly.
Concept
Autoencoders are a sort of neural community used for unsupervised studying. Their structure consists of three primary parts:
- Encoder. The primary a part of the neural community that takes enter information and regularly reduces its dimensionality by means of its layers, in the end reaching the bottleneck.
- Bottleneck. The community layer with the smallest dimensionality that incorporates the latent illustration of the enter information.
- Decoder. The a part of the community linked to the bottleneck output that regularly expands the info’s dimensionality. Consequently, at its final layer, it returns information of the identical measurement as was initially handed to the encoder.

For pictures, the encoder and decoder are often introduced as convolutional neural networks.
In autoencoders, our final objective throughout coaching is to make the community remodel the enter information right into a extra compressed illustration within the bottleneck with out dropping an excessive amount of data. Throughout inference, we will go the info to the encoder, extract the ensuing embedding from the bottleneck, after which use it for our personal functions.
Let’s perceive how coaching works in autoencoders.
Coaching
A wonderful thing about autoencoders is that they don’t require any labeled information! Let’s see how they work.
As talked about earlier than, an enter picture is handed to the community, the place it’s compressed to a smaller measurement after which reconstructed to the unique dimension. The query we should always ask ourselves is what we would like the decoder to output.
As you could possibly have guessed, the decoder can merely attempt to reconstruct the unique picture from the compressed illustration within the bottleneck. Why achieve this?
The concept behind that is easy:
- If the bottleneck’s compressed illustration captures the principle options of the encoder’s enter properly, then it needs to be comparatively straightforward for the decoder to make use of that data to reconstruct the unique picture.
- If the bottleneck fails to seize the principle options, the decoder received’t be capable of reliably reconstruct the unique picture. Thus, the mannequin might be penalized for a poor compressed illustration.
This fashion, by asking the decoder to reconstruct the unique picture, we implicitly pressure the encoder to provide a wealthy but compressed latent illustration, serving to the decoder effectively obtain its job.
The house to which the enter information is projected within the bottleneck is known as the latent house.
Reconstruction loss
Given the unique picture and the reconstructed picture from the decoder, what’s the easiest option to evaluate the generated high quality? The plain reply is to check the 2 pictures pixel-wise utilizing the MSE loss, which, within the context of autoencoders, is known as the reconstruction loss.

The calculated loss worth is then used to carry out backpropagation to replace the mannequin’s weights.
Latent house dimension
The latent house dimension is a crucial hyperparameter that immediately impacts the decoder’s efficiency.
On the one hand, the latent house dimension needs to be adequate to effectively encode the important thing enter options. However, it shouldn’t be too giant to keep up a excessive compression charge.
One well-known instance is Steady Diffusion. It makes use of an autoencoder to rework the enter picture, 512 x 512 x 3, containing 786,432 values, right into a 64 x 64 x 4 picture with 16,384 values, leading to a compression ratio of 48x.
Different autoencoder purposes
One trick for coaching autoencoders is to have them study to take away noise from pictures. The concept is easy: since autoencoders are good at reconstructing unique pictures, we might add slight noise to the enter pictures after which ask them to reconstruct the unique pictures.
A wonderful thing about this technique is that for coaching, it’s adequate to have solely the unique pictures, to which you’d then apply noise.

One other cool utility of autoencoders is picture inpainting, which entails passing pictures with masked patches to a mannequin so it could actually unmask and fill within the lacking picture elements.
Equally, autoencoders could be educated to take away particular objects from pictures. That is notably helpful for eradicating watermarks.

Blueriness drawback
In actuality, regardless of its simplicity, the MSE loss isn’t excellent for autoencoders. One frequent drawback with utilizing it’s a tendency for the decoder to generate pictures with blurry pixels.
For instance, we might think about a picture of measurement 512 x 512 with two vertical, non-overlapping black-and-white areas. We then take a horizontal row of that picture whose pixels seem like this:
[… 0 0 255 255 255 …]
The mannequin doesn’t have any information of the picture construction; it solely tries to reduce the MSE loss. Even when, for that picture, a mannequin made a prediction like [… 0 0 0 255 255 …], which remains to be excellent as a result of the area is shifted by just one pixel, the MSE loss on this case could be increased than within the case under, which a mannequin would possibly desire:
[… 0 0 127 255 255 …]

Within the latter state of affairs, regardless of the decrease MSE, the center pixel represents a blurry edge, which is visually unappealing.
This drawback is addressed in additional superior autoencoder variations with adjusted loss capabilities.
Conclusion
As we will see, autoencoders are a easy but highly effective idea. By coaching the decoder to reconstruct the unique picture from compressed information, we regularly alter the encoder to provide extra informative options that may then be extracted for downstream duties.
Along with information compression, we noticed that autoencoders produce other purposes, reminiscent of denoising pictures, performing picture inpainting, and eradicating objects from pictures.
All pictures except in any other case famous are by the writer















