Installing ESRGAN and SFTGAN

Disclaimer

Since I use Windows 10, this tutorial is written from this perspective. If you also are running Windows 10 and are using an Nvidia Graphics card, then this process should get you up and running without too much fuss.

If you are using Linux, many of these steps may actually be easier since you should already be familiar with terminal commands. However, if you're using iOS... well, good luck!

System Requirements

While it is possible to run the AI upscaling algorithms on the CPU, it is extremely inefficient to do so. For this reason, I consider having a CUDA supported graphics card to be a requirement. Most modern NVIDIA graphics cards in the GTX series, and all of RTX series supports it.

CUDA is the software that allows the AI to take advantage of the highly parallel architecture of the GPU, computing the result of many neural actions simultaneously instead of one-at-a-time.

With regards to VRAM, a graphics card with more memory is better but for the case of upscaling retro game textures, 3GB should be more than enough.

Installing CUDA

If you want to take advantage of GPU acceleration for AI, then you must install CUDA.

Download the installer for your operating system here.

Note: While other versions of CUDA may work, I've linked version 9 above. I believe there was a compatibility issue between CUDA 10 and pytorch which prevents ESRGAN and SFTGAN from working. Feel free to experiment.

You can disregard the patches; I don't believe those are necessary.

Installing ESRGAN

The following section will walk you through cloning the ESRGAN repository onto your computer as well as installing all the dependent python packages it relies on to function.

Using GitHub

If you aren't familiar, GitHub is a repository used for (mostly) open source software developers. You can browse and find many projects hosted there and "clone" it to your own computer to either use or collaborate with the author(s). Please be aware of any licenses that may be attached to the respective projects and use at your own discretion.

To clone a project, you can simply download a compressed "zip" file containing the entire project (except for its dependencies) and then extract the contents of the zip file anywhere on your computer that you want. Alternatively, you can also use GitHub Desktop which makes it easy to keep your project up-to-date.

Navigate to the ESRGAN github page and clone the project to your computer.

Most well structured (at least in my opinion) GitHub pages will have a section containing the required dependencies that the application relies on to function, many of which are Python packages which you can install using PIP (see below).

In this case, we can see that ESRGAN requires us to install Python (version 3), PyTorch, and two Python packages called numpy and opencv-python.

So let's get started!

Installing Python and PIP

Many of the open source AI applications are built and ran using Python.

Download Python 3 here for your operating system.

I'm using 3.6, but I'm pretty sure anything newer than version 2 should work.

Make sure you select the options to install PIP and to add Python to the system environment variables (system path).

This should be true by default, but it's good to check.

PIP will allow you to easily install dependent applications (called dependencies) from terminal.

Having Python added to your system variables allows you to call "Python" and "PIP" without first navigating to the directory where they're installed, which is incredibly handy.


Using Terminal

To install all the package dependencies for the AI algorithms, we must use terminal commands. For Windows, this just means using command prompt which is installed by default on all Windows machines. To open command prompt, simply type "cmd" in the search bar next to the start button. The very first match should be Command Prompt. I would advise that you create a shortcut to this application since we will use it quite a bit. I would also recommend that you run this application as administrator, although that may not be necessary.

*From here on out, I will be referring to Command Prompt as Terminal.

If you are not very familiar with terminal commands in Windows, here is a good cheat sheet, but we will only use a tiny fraction of these commands.

A quick word on notation: It is very common for terminal commands to be represented as such:

$ [application] [command] [arguments] [-option(s)]

Note that you do not need to input the $. It is simply used to indicate where the terminal input begins.

Example:

$ python -h

In this case you would enter "python -h" (without the quotes of course) into the terminal. This example will call the program "Python" and using the "-h" option will return a help screen showing all the other options that can be used. If you just tried it and it didn't work, then check to make sure that it correctly added your Python directory into the system environment variables. Later on we will use "python test.py" which will use Python to run a script named "test.py".

Another example:

$ pip install numpy

In this case you simply enter "pip install numpy" and it will automatically search for the most recent version of the Python package with that name and install it. Very handy!

PIP is the application, install is the command, and numpy is the argument.

Installing Pytorch

Go to the GET STARTED section of the official PyTorch site.

Select the latest stable build, your OS, PIP, your version of Python (not 2.7!) and your version of CUDA that you installed earlier (I recommended 9.0).

It will display terminal commands for you to run (just copy and paste into your terminal/command prompt and hit enter).

Run them one at a time. Torch will take a little while to download and install (around 2-3 minutes), but Torch Vision should only take a few seconds.

You may notice a few odd things about these commands:

  1. The command line starts with "pip3" instead of "pip". If you only have Python 3 installed, there is no need to be explicit. You could also use "pip" and it would still work.
  2. The argument of install command isn't just "Torch" but is a long URL instead. This is because there are many builds based on many different variables such as the version of Torch you want, the OS you're using, the version of Python you're using, etc., so it just points you directly to one of many possible variants.

Install other Python Dependencies

Now for the easiest part. In your terminal, type the following commands:

$ pip install numpy

After it finishes, type the following command:

$ pip install opencv-python

Download ESRGAN Models

An up-to-date list of models can be viewed and downloaded here.

Just download them into your models folder in your ESRGAN directory.

That's it! You now have everything you need to run ESRGAN. Move on to my User Guides to learn how to put them to use!