How to run PULSE (face-depixelizer) on Linux on Windows 10 (WSL)? Tutorial

One spring evening in 2020, I read an article about the face-depixelizer neural network . After studying it, it turned out that this is a kind of frontend for the PULSE engine . Which is based on the StyleGAN neural network (generates faces with random features).



In this tutorial, I'll walk you through the steps and show how I installed Ubuntu on Windows 10 (WSL), set up an environment for experimenting with PULSE , uploaded another original photo and got a good result.

The result of restoring the original image in PULSE

Morph animation and video tutorial - further.





What has been given to us





Face-Depixelizer is a frontend for working with PULSE.



PULSE is an engine based on the StyleGAN neural network. Its meaning is that it restores images of a person's face from a fuzzy photograph. And by the way, this is a scientific work for CFV .



StyleGAN , a generative adversarial neural network from NVidia, generates a random face of a non-existent person (in fact, it will be funny if such a person already exists).





PULSE , finally, will tell us roughly what the same person who blinked in this photo looks like!





Taking on the PULSE





I wondered what was under the hood of PULSE and, in general, how it could be started locally.

For interest, having looked diagonally through a scientific article, I began to think about how to start and how to establish all this (despite the fact that I had never set myself a "neural network").



And I started by saying that as soon as possible, before the github fell (if you know what I mean), I switched to the PULSE project . Where the author indicated this installation option: anaconda and python. Those. in any case, platform-specific packages (libraries) are required. I am more of a Windows user than Linux. But, all the same, I would like to run without editing and tedious selection of libraries. And without Linux, this cannot be done.



Some time ago, some of the IT specialists were talking about Linux in Windows. And I'll tell you that, for me - in vain. The thing is convenient, although it has not yet been completed.

WSL , the Windows Subsystem for Linux, allows developers to run the GNU / Linux environment, including most command line programs, utilities and applications, directly on Windows without any modification, eliminating the need for a separate virtual machine.


Those. this is access to the linux command line from windows. A terminal with Linux is as easy to start as cmd. Conveniently.



Let's get started



To work with the terminal, here and in the video I will use Windows Terminal (from the Windows Store).


In short



Checking the requirements



  • NVidia video card with CUDA support (StyleGAN neural network uses CUDA). List of supported video cards here
  • NVidia CUDA WSL2 ( , ).
  • Windows 10 version 2004 build 20150 ( Windows Insider Program ), .
  • WSL2 (4.19.121 ; Windows) linux .
  • Ubuntu 18.04 WSL2 Windows Store.


Ubuntu





CUDA



  1. CUDA
  2. .




Download and install anaconda.



Install PULSE



  1. Downloading from github PULSE
  2. Editing pulse.yml:



    • Add channels anaconda, conda-forge
    • Removing references to specific assemblies
  3. Install the PULSE environment using the edited file
  4. Checking the performance of Pytorch and the CUDA Toolkit in Python.


Experimenting



  1. Using pip update jupyter notebook to the latest version
  2. Adjusting the image (in the issue they write that PULSE works with a square image of 1024 * 1024 and three RGB channels, i.e. without transparency)
  3. We increase / decrease the number of steps and the error
  4. ...
  5. PROFIT!




Above is a morph animation created from intermediate images.



As the saying goes: β€œit's better to see once than hear a hundred times”. The video shows all the steps, starting with updating WSL2 and installing Ubuntu.







And now…



More details



Requirements



Once again I will repeat the requirements (... and after the hundredth editing, I will remember Fowler for the hundredth time):



  • Windows 10 version 2004 build 20150 or higher
  • WSL2 (version 4.19.121 and higher)
  • Ubuntu 18.04 for WSL2 is the distribution itself from the Windows Store. Installed after all Windows 10 Insider updates are rolled forward , incl. WSL2
  • NVidia Driver WSL is an experimental version of drivers with support for the new version of WSL2. Requires consent to participate in the NVidia Experimental Program. But not every card will work .


OS preparation



Windows 10


The goal : Windows 10 version 2004 build 20150 and above



pretreatment :



  1. Launching updates
  2. Then, using the application winver, we check the current version of Windows
  3. If your Windows version is lower than Windows 10 version 2004 build 20150, then you will need to follow the steps below
  4. And if everything is ok, congratulations, you don't have to join the Windows Insider Program! Feel free to proceed to the next stage!


What we do :



  1. Entering the Windows Insider Program
  2. Further, in the system parameters "Update and Security":

    • Insider Program Tab (if blank, see Troubleshooting section below):



      1. Evaluation Options: Early Access
      2. Click "Start".
    • Windows Update tab:



      1. In the "Advanced" be sure to allow "When updating to receive updates for other Microsoft products" (this is for installing WSL2 4.19.121 and higher)
      2. We are updating.


Check : launch winver. In the dialog box that opens, look at the version.



NVidia Driver CUDA WSL


Purpose : Installing the latest version of NVidia Driver CUDA WSL



What do we do :



  1. Go to the page
  2. If you have not registered yet, we register; agree to participate in the experimental program
  3. Download and install.


Verification : will be at the stage of "CUDA operability check"



WSL2


The goal : WSL2 version 4.19.121 and higher



pretreatment :



  1. We update Windows to Windows 10 version 2004 build 20150 and higher, if not update in the steps above
  2. If, after executing in the terminal:



    wsl --update
    the contents of the help will be displayed (a la wsl --help), then you have an old version. Then proceed to the steps below
  3. If a version from 4.19.121 and higher is displayed, then skip this stage.


What we do :



  1. Launch PowerShell as an admin and execute sequentially:

    • We include the additional component "Windows Subsystem for Linux":



      dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    • Then, enable the "Virtual Machine Platform" component:



      dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    • We reboot.
  2. Updating WSL:



    wsl --update
  3. Next, we install the second version of WSL - as the default for all future distributions:

    To do this, launch PowerShell with admin rights and execute:



    wsl --set-default-version 2


Check : command:



wsl --update
[after installing the update] will display version 4.19.121 and higher.



Ubuntu 18.04 on WSL2


The goal : Ubuntu 18.04 on WSL2



pretreatment : if (I have not tested the following branch, but it would be nice if you specify in the comments, who faced if helped) on the WSL was previously installed Ubuntu 18.04:



  • We check it in the list:



    wsl --list --all -v
  • For this distribution, switch the WSL version to ver.2:



    wsl --set-version Distro 2


    For example:



    wsl --set-version Ubuntu-18.04 2
  • We reboot.


What we do :



  1. Go to the Windows Store
  2. We are looking for Ubuntu 18.04 and install


Check : open a terminal, execute:



wsl --list --all -v


see Ubuntu 18.04 Version 2



Preparing Ubuntu



Pre-preparation


  1. Updating package indices:



    sudo apt update
  2. Install cmake (to install dlib):



    sudo apt install cmake
  3. To unpack zip archives, install, for example, the unzip utility :



    sudo apt install unzip


Installing the CUDA Toolkit


  1. Add CUDA to the package index:



    sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
    
    sudo sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
    
    sudo apt update
  2. Install the CUDA Toolkit:



    sudo apt install -y cuda-toolkit-11-0


Checking the performance of the CUDA Toolkit




To do this, run the examples (the deviceQuery program is informative):



  1. Downloading:



    wget https://github.com/NVIDIA/cuda-samples/archive/master.zip
  2. Unzip:



    unzip master.zip
  3. Go ahead and build (everything):



    make
  4. Run:



    ./bin/x86_64/linux/release/deviceQuery


    The application will display a list of compatible devices.


Installing Anaconda


  1. Download the distribution from the link
  2. Run:



    bash Anaconda3-2020.02-Linux-x86_64.sh


    During installation:



    1. Agree to a license
    2. We leave PREFIX
    3. We agree to initialization
  3. Restart the terminal, or run:



    source ~/.bashrc


Setting up the environment in anaconda



Configuring PULSE


  1. Downloading:



    wget https://github.com/adamian98/pulse/archive/master.zip
  2. Unzip:



    unzip master.zip
  3. Create a backup of pulse.yml:



    cp pulse.yml pulse.yml.bak
  4. Fix pulse.yml:



    1. Add channels (these are package sources):

      • conda-forge
      • anaconda
    2. We remove all references for a specific version of the package.

      Example : zstd=1.3.7=h5bba6e5_0remove the last part from the line " ", starting with the equal sign: " =h5bba6e5_0". As a result, we get " zstd=1.3.7".



      We do it either by hand or through the sed utility:



      sed '/==/b; s/=\([^=]*\)$//' pulse.yml > pulse1.yml


      : , , "==", regexp
  5. pulse1.yml:



    conda env create -f pulse1.yml
  6. , - NotResolverPackage. libfortran 3.0.1:



    1. conda libfortran
    2. Anaconda Cloud Files (3.0.1), , , osx-64
    3. Anaconda Cloud, cloud-forge 3.0.0-1 linux-64. !
    4. pulse1.yml libfortran=3.0.1 libfortran=3.0.0=1
    5. :



      conda env create -f pulse1.yml
    6. , !
    7. If you need other packages, be sure to pay attention to the channels, add if necessary.
  7. We are waiting for it to be installed
  8. Then we activate:



    conda activate pulse


Checking the performance of Pytorch and CUDA in python


  1. This script:



    from __future__ import print_function
    import torch
    x = torch.rand(5, 3)
    print(x)


    Should output something like this:



    tensor([[0.3380, 0.3845, 0.3217],
    	[0.8337, 0.9050, 0.2650],
    	[0.2979, 0.7141, 0.9069],
    	[0.1449, 0.1132, 0.1375],
    	[0.4675, 0.3947, 0.1426]])
  2. And this one:



    import torch
    torch.cuda.is_available()


    Will output:



    True


At this stage, in theory, you can stop. But I went ahead and installed jupyter notebook for experiments.

Jupyter Notebook is an incredibly powerful tool for interactively developing and presenting data science projects.




Working with PULSE





Let's get started




  1. We activate the pulse environment:



    conda activate pulse
  2. Installing Jupiter:



    pip install jupyter
  3. Run:



    jupyter notebook
    And further:

    1. Create a new notebook New-> Python3 (notebook)
    2. Paste the code from the file there
    3. We throw the source file into the root of the project, renaming it to source.png:



      cp /mnt/c/Users//Desktop/face1.png source.png
    4. We launch. We wait


Notes


  1. , 500-800, eps
  2. :

    1. , , 1024*1024
    2. PNG
    3. (RGB) RGBA
  3. : "Could not find a face that downscales correctly within epsilon", :



    steps \ eps, , (steps), eps L2. .



    :



    BEST (400) | L2: 0.0013 GEOGROSS: | TOTAL: | time: ...


    Where 400 is the (specified) achieved number of steps (steps), L2 is the value of interest, it must be less than the specified eps (as I understand it, this is the accuracy of optimization; comrades AI developers, tell me what it is?).



    So, for example, you need to increase one thing or all together: steps (put more than 400) and \ or eps (put eps = 0.0013 and more, i.e. it should be so that eps> = L2) ...

  4. If you want to see intermediate photos for each step, add the parameter -save_intermediate

    Images are saved to the folder runs/: in the folder HR- high resolution, in the folder LR- low resolution)


Possible problems are below.



Solution of problems



If you not only encountered errors, but also solved them, write, I will add here.


White Screen in Windows Insider Program


Option : you are under a different user, you do not have enough privileges.

Solution : see link . But I solved it without changing the registry.



CUDA samples do not start


Options :



  1. Your graphics card is not supported
  2. You haven't rolled the latest WSL2
  3. You have not installed the latest (experimental) version of NVidia Driver CUDA WSL


jupyter notebookThrows an error at startup


Error : Start : This command cannot be run due to the error: The system cannot find the file specified.

Solution : copy the connection string to the browser (I did not understand other solutions).



When starting PULSE, an error constantly falls out


Error : Google Quota Exceeded

Solution : copy the source file from me and throw it to the root - to the cache folder (create it if it is not there).



Or:



  1. Download the file using the first google link from PULSE.py
  2. Rename it using the template md5hash _synthesis.pt, where md5hash is the md5 hash of the downloaded file (in the current version it is 6b943ee69b8491ac40e8e9ced6175659_synthesis.pt)
  3. We throw it into the cache folder (create it if it is not in the root of the directory where PULSE is located)


When starting PULSE or checking Pytorch throws an error


Error : ModuleNotFoundError: No module named 'torch'

Solution : If you have checked pytorch and it works, then it means that you have not activated the pulse environment. To do this, run the following command:



conda activate pulse


Conclusion



The next step is to study StyleGAN and other "neural networks" based on it.

I would be glad to read your comments on the article, recommendations (including on the presentation, since this is my first public article), amendments.



Thank you all for reading!



References and links to utilities, drivers



  1. Installation instructions for NVidia Driver for CUDA on WSL
  2. NVidia drivers for CUDA under WSL
  3. List of supported CUDA video cards
  4. CUDA examples
  5. Instructions for installing WSL2 on Windows 10
  6. Windows Insider Program Help & Introduction - Windows Early Access
  7. Instructions for installing Anaconda on Linux system
  8. List of Anaconda distributions
  9. Jupyter Notbook - Analytics and Experiments
  10. PULSE repository
  11. Face-Depixelizer repository
  12. StyleGAN repository



All Articles