Artificial Intelligence

Machine Learning in Linux: CodeFormer – face restoration

With the availability of huge amounts of data for research and powerful machines to run your code on with distributed cloud computing and parallelism across GPU cores, Deep Learning has helped to create self-driving cars, intelligent voice assistants, pioneer medical advancements, machine translation, and much more. Deep Learning has become an indispensable tool for countless industries.

CodeFormer is command-line software which offers blind face restoration. This aims at recovering high-quality faces from the low-quality counterparts suffering from unknown degradation, such as low-resolution, noise, blur, compression artifacts, etc.

The software employs a Transformer-based prediction network to model global composition and context of the low-quality faces for code prediction, enabling the discovery of natural faces that closely approximate the target faces even when the inputs are severely degraded.

Note, CodeFormer’s license does not meet the criteria to be considered an open source license.

Installation

There are quite a few steps to install CodeFormer, but everything goes smoothly.

If you’re installing CodeFormer on a fresh installation, you may need additional packages such as git. The software requires conda which a fresh install of Ubuntu is also missing.

One way to obtain conda is to download Anaconda, a distribution of the Python and R programming languages for scientific computing, that aims to simplify package management and deployment.

$ wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh

This version is a 738MB download.

Run the shell script:

$ bash Anaconda3-2022.10-Linux-x86_64.sh

You’ll be asked to accept Anaconda’s license and whether to initialize Anaconda3 by running conda init.

For changes to take effect, close and re-open your current shell.

Next, clone CodeFormer’s GitHub repository, and change into the newly created directory.

$ git clone https://github.com/sczhou/CodeFormer
$ cd CodeFormer

We next create a new anaconda environment.

$ conda create -n codeformer python=3.8 -y

Activate the environment.

$ conda activate codeformer

Next, we install Python dependencies.

$ pip3 install -r requirements.txt

This downloads many packages including numpy, scipy, torch (which is 887MB).

$ python basicsr/setup.py develop

$ conda install -c conda-forge dlib (only for dlib face detector)

Download the facelib and dlib pre-trained models (they will be saved to weights/facelib directory)

$ python scripts/download_pretrained_models.py facelib

Now download the CodeFormer pretrained models:

$ python scripts/download_pretrained_models.py CodeFormer

Next page: Page 2 – In Operation and Summary

Pages in this article:
Page 1 – Introduction and Installation
Page 2 – In Operation and Summary

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments