Install CodeFormer Inside Docker Container in Linux

Install CodeFormer Inside Docker Container in Linux

Face images captured in low-quality conditions, usually suffers from various degradation, such as noise, blurring, etc. Restoring these images is a challenging task. CodeFormer (Codebook Lookup Transformer) is a face restoration model that takes a low-quality image of a face as input and predicts a high-quality image of a face.

This tutorial explains how to install CodeFormer inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Create Docker image

Create Dockerfile and add the following content:

FROM nvidia/cuda:12.0.0-runtime-ubuntu22.04

WORKDIR /codeformer

RUN apt-get update \
    && apt-get install --no-install-recommends -y  \
        libgl1-mesa-glx libglib2.0-0 python3 python3-pip git \
    && git clone https://github.com/sczhou/CodeFormer.git /codeformer \
    && pip3 install -r requirements.txt \
    && python3 basicsr/setup.py develop \
    && python3 scripts/download_pretrained_models.py facelib \
    && python3 scripts/download_pretrained_models.py CodeFormer \
    && apt-get purge --autoremove -y git \
    && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["python3", "inference_codeformer.py"]

The nvidia/cuda is used as a base image. So, make sure you have NVIDIA graphics card on the system.

Run command to create Docker image:

docker build -t codeformer .

Testing CodeFormer

Create directory to store input images:

mkdir ~/inputs

Download sample image:

sudo curl -o ~/inputs/test.jpg https://raw.githubusercontent.com/sczhou/CodeFormer/master/inputs/whole_imgs/03.jpg

Run a command in CodeFormer container to perform face restoration:

docker run -it --rm \
    -v ~/inputs:/codeformer/inputs \
    -v ~/results:/codeformer/results \
    codeformer -w 0.5 --input_path inputs/test.jpg

Output saved in ~/results directory.

Few face restoration results using images from LFW dataset:

Face restoration using CodeFormer

Remove Docker image

To remove CodeFormer image, run the following command:

docker rmi codeformer

Leave a Comment

Cancel reply

Your email address will not be published.