Facial Reconstruction using Autoencoders

栏目: IT技术 · 发布时间: 3年前

内容简介:Many of you may have witnessed the application of facial recognition or reconstruction in crime dramas or spy thrillers. Yes, it helps to solve a case so why not build your own. In this article, we will be focusing on how to reconstruct faces from noise co

Learn how to reconstruct/denoise images using autoencoders from scratch

May 26 ·4min read

Facial Reconstruction using Autoencoders
Image by Author

Many of you may have witnessed the application of facial recognition or reconstruction in crime dramas or spy thrillers. Yes, it helps to solve a case so why not build your own. In this article, we will be focusing on how to reconstruct faces from noise containing or damaged images. This is also known as Image Denoising. Using unsupervised deep learning techniques or rather self-supervised deep learning techniques of autoencoders, this program helps to reconstruct or denoise facial images.

Facial Reconstruction using Autoencoders

Image by Author

What are autoencoders ?

Autoencoders, as the name suggests, encodes itself. It takes inputs and makes them go through hidden layers that are supposed to give an output similar to the input. Hence, the whole aim is to get identical results to input fro the output. There are two components of an autoencoder i.e. encoder and decoder. The encoder has the job to compress the input data into smaller encodings. Whereas decoders learn to build output, the same as the input using the encodings. They have a wide range of applications from recommender systems to classification problems too. Here we will be using convolutional autoencoders (CAEs) which are built upon standard network components, i.e., convolutional layers and skip connections that can outperform state-of-the-art methods which employ adversarial training and sophisticated loss functions.

Data: Dataset and Pre-processing

We will be using the LFW Dataset for this project. It is a database of face photographs designed for studying the problem of unconstrained face recognition. The data set contains more than 13,000 images of faces collected from the web. Each face has been labeled with the name of the person pictured. 1680 of the people pictured have two or more distinct photos in the data set. For preprocessing we will covert raw matrices into images obtained from the dataset and change the color system into RGB. We will also be taking into consideration, various attributes related to the facial image like the shape of the nose, heavy makeup, smiling, etc.

Building the Model

Gist by Author

Here we build a custom model builder where we get to specify the image dimensions and output representation. We have used a Keras based model to do so as it is easy to apply. In the code snippet, img_shape signifies the image dimensions and code_space is the size of output representation.

The code_space needs to be appropriately chosen as smaller the number, it will compress the image that much, but fewer features will be considered and we won’t be able to get accurate results. In this code, I have taken a code_space of 10000 for demonstration purposes.

We build the encoder and decoder separately in the same function which are a single-layered neural network respectively.

Training and Testing

Gist by Author

Since the model is ready and data is processed, its time to train!

We will be training the model on regular faces that are present in the dataset with the aim that the model will reconstruct the same face. I tried and visualized the results with a different number of epochs. I finally concluded that 20 epochs were enough to get a good result with training loss at 0.0020 and testing loss at 0.0025.

Facial Reconstruction using Autoencoders
Image by Author

Now that we have a good enough model, we will try to add noise to the original image and map it through our model to give a clearer one. For adding noise we will use the method of Gaussian noise and retrain are model over it.

Facial Reconstruction using Autoencoders
Image by Author

After retraining the model to map noisy images to a clearer one we get the training loss as well as the testing loss of 0.0038 after 25 epochs. Visualized results are as followed:

Facial Reconstruction using Autoencoders
Image by Author

More Applications of Autoencoders

Another cool application of autoencoders in the same field is of making DeepFakes . This is used in numerous ways such as face swaps where the encoder and decoder are from different models.

Another application of autoencoders is recommender systems where it can accurately rate, let’s say movies on a scale of 1–5 based on previously reviewed movies by a user.

Other applications include dimensionality reduction, image compression (as used in this case too), feature extraction, image generation, and sequence to sequence prediction.

Source Codes and Additional Resouces

Check out the entire code on my GitHub with relevant links to the data set as well.

Addition Reading links for autoencoders.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

WebKit技术内幕

WebKit技术内幕

朱永盛 / 电子工业出版社 / 2014-6 / 79.00元

《WebKit技术内幕》从炙手可热的HTML5 的基础知识入手,重点阐述目前应用最广的渲染引擎项目——WebKit。不仅着眼于系统描述WebKit 内部渲染HTML 网页的原理,并基于Chromium 的实现,阐明渲染引擎如何高效地利用硬件和最新技术,而且试图通过对原理的剖析,向读者传授实现高性能Web 前端开发所需的宝贵经验。 《WebKit技术内幕》首先从总体上描述WebKit 架构和组......一起来看看 《WebKit技术内幕》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具