GFPGAN is a set of tools and a ready-to-use neural network (you can train your own) to enhance faces in photographs, they also promise to improve the no face places, but somehow I did not notice the enhancement effect, although they resize it well! Project page: github.com/TencentARC/GFPGAN. Everything works on Linux, of course, and it works fine, but today I’m going to use it on Windows, simply because Windows already has Linux called WSL!
I`ll need:
– Windows 10-11 latest version
– Nvidia video card with CUDA (I have rtx 2070), but it can also be done with only CPU!
– CPU with virtualization (almost all CPUs have it)
Go to Powershell console as administrator
Install WSL
wsl --install
The first version of WSL is installed without asking anything, but we need the second one, so we do
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
After the last command, Windows will want to reboot, that’s good! Go to the BIOS and enable the virtualization item:
Hyper-V for Intel
SVM mode for AMD
We return to the Powershell console under the administrator and do
wsl --set-default-version 2
Want us to download here docs.microsoft.com/ru-ru/windows/wsl/install-manual#step-4—download-the-linux-kernel-update-package just download and run WSL 2 Linux kernel update package for 64-bit computers.
Repeat
wsl --set-default-version 2
Now we install Ubuntu 20.04.4 LTS as one more application in the Microsoft Store
In the Powershell console, we see what version of WSL we have in Ubuntu
wsl -l -v
got it
NAME STATE VERSION Ubuntu20.04LTS Running 2
All went well!
We start Ubuntu, as an application through Start we get a black window, this is the Ubuntu console
By the way, congratulations, we already have a video card because the Nvidia driver is already installed
nvidia-smi
Sun Apr 3 14:53:22 2022 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 495.53 Driver Version: 497.29 CUDA Version: 11.5 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... On | 00000000:0A:00.0 On | N/A | | 0% 54C P8 21W / 175W | 442MiB / 8192MiB | N/A Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+
Upgrade
sudo apt-get update && sudo apt-get upgrade -y
I know that it will be necessary to install GCC (actually, rather not, but just in case)
sudo apt install gcc
In case of some errors you have to execute before
sudo apt --fix-broken install
Install CUDA
sudo apt install nvidia-cuda-toolkit
Lets check version
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA Corporation Built on Sun_Jul_28_19:07:16_PDT_2019 Cuda compilation tools, release 10.1, V10.1.243
Install Conda
Python has a bug or a feature: what is written in one version may not work in others, the same applies to different versions of modules. And conda creates an environment for each program with the necessary versions and no update will break it.
We download a minimalist version of Conda
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash Miniforge3-Linux-x86_64.sh
We answer yes to all questions during installation.
Close and open Ubuntu window and run
conda config --show
We see conda configuration so it works
Lets create a Python environment for GFPGAN version 3.7
conda create --name GFPGAN python=3.7
It starts downloading everything it needs and it should be noted that the speed is very low, I blame WSL
Lets activate the environment, it only affects Python
conda activate GFPGAN
Install GFPGAN
git clone https://github.com/TencentARC/GFPGAN.git
open its floder
cd ./GFPGAN
You need to install the following before, according to the creators of GFPGAN
pip install basicsr
pip install facexlib
pip install -r requirements.txt
python setup.py develop
pip install realesrgan
Download the neural networks
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models
wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P experiments/pretrained_models
Now we are in folder GFPGAN from Windows you can open this Linux folder with path \\wsl$\Ubuntu20.04LTS\home\YOUR_USER\GFPGAN
put the photos here /inputs/whole_imgs/ and the result will be here /results/restored_imgs/
We execute comands one by one, the photo must be taken after each command
python inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.2 -s 2
python inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.3 -s 2
In the first command, the neural network is 1.2 it use only CPU, in the second 1.3 with CUDA, the last digit says that it is increased by 2
Impressive! Neural network 1.3 renders more alive face! If you’re not impressed, there’s a face comparison in the /results/cmp/ folder! From the initial image on the left, to the result on the right!
[…] « Resize and enhance old photos with GFPGAN on Windows via WSL2 and a card with CUDA (or without)! […]
[…] to configure a video card and GFPGAN I have already described here Resize and enhance old photos with GFPGAN on Windows via WSL2 and a card with CUDA (or without)!. Here we use python without Conda, so to speak, but it is necessary for GFPGAN, but we do not run […]
Hi. You can use a free online tool to enhance image quality https://freetools.site/image-editors/enhance-quality
FYI, I’m running Windows 10 home edition and couldn’t get Hyper-V installed because hyper-V only comes installed with windows pro, etc. However it can be enabled on home edition, instructions are at: https://answers.microsoft.com/en-us/windows/forum/all/enabling-hyper-v-on-windows-10-home/2e9a91c4-564c-4d42-833f-956515f1f095