GFPGAN: Free AI Tool to Fix/Restore Faces & Upscale Images

Portrait Before and After Using GFPGAN
Portrait Before and After Using GFPGAN

GFPGAN is a tool that allows you to easily fix or restore faces in photos, as well as upscaling (increasing the resolution of) the entire image. It’s also completely free to use.

It’s great for face and photo restoration and upscaling images for old or damaged photos. What’s interesting is that you can also use it for fixing AI art portraits. Since current AI art generation software often has problems generating great looking faces, this tool is perfect for fixing AI generated faces.

The way we will use GFPGAN is in Google Colab. Google Colab is a way to use Python in your browser. It works similar to Google Docs, but for Python.

You don’t need to know anything about Google Colab or coding. It may look a little bit intimidating at first, because you’ll see code around, but you don’t need to touch it. All you have to do is click a few buttons, upload your pictures, and then download them.

In this tutorial we’ll assume you’re not familiar with Google Colab so we’ll try to be as beginner-friendly as possible.

tl;dr AI News Section Preview
tl;dr AI News Section Preview

Sidenote: AI art tools are developing so fast it’s hard to keep up.

We set up a newsletter called tl;dr AI News.

In this newsletter we distill the information that’s most valuable to you into a quick read to save you time. We cover the latest news and tutorials in the AI art world on a daily basis, so that you can stay up-to-date with the latest developments.

Check tl;dr AI News

GFPGAN User-Friendly Alternatives

There are some other websites that allow you to use GFPGAN in a more user friendly way. A great one that seems to be free and doesn’t seem to have any limitation is Photo restoration with GFP-GAN on Baseten.co.

You just upload the image and wait a little bit for your image to be generated. There are no sign-ups or anything.

It should be great for you for casual usage, and if you don’t want to use GFPGAN with Google Colab. Here are a few demos of pictures generated with Stable Diffusion that it fixed.

Another excellent one, that’s fast and easy to use, is GFPGAN on HuggingFace.co.

Quick Demo (Video)

We’ll start off with a 3 minute demo so you can see that it’s really easy to use GFPGAN with Google Colab. This is the entire process from start to finish.

Copy of GFPGAN in Your Google Drive

The first thing we want to do is visit the Google Colab Notebook for GFPGAN (https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo). You can also find that link on the Github page for GFPGAN, as you may have seen in the video.

The Google Colab Notebook is similar to any other Google Doc. To start off we’ll want to save it to our own Google Drive. To do this go to File > Save a copy to Drive.

Screenshot of Google Colab Menu File > Save a copy to Drive
File > Save a copy to Drive

Now a new tab should appear with the copy of the notebook. This one is also located your Google Drive under the name Copy of GFPGAN_inference.ipynb. You can rename it anything you want. I typically remove the Copy of.

You can close the tab with the original notebook as we’ll only be using the new one now.

Make Sure We’re Using a GPU

Next we want to make sure our notebook is using a GPU. Google allocates us one of a few GPU models automatically. Usually the GPU is enabled by default but we should make sure. To do this go in the menu to Runtime > Change runtime type. A small window should appear, and under Hardware accelerator it should be a dropdown with GPU selected. If it’s not selected then change it to GPU.

Run GFPGAN to Fix & Upscale Images

Now we can start using the GFPGAN notebook to fix and upscale images.

We’ll just have to run a number of “cells” or “code blocks” by hovering over them and clicking a play button in the top left corner of the blocks.

Run “1. Preparations” Cell to Setup GFPGAN

To start off we’ll run the cell under 1. Preparations. This code sets up GFPGAN on our notebook. Just click the play button next to it, where it says Clone GFPGAN and enter the GFPGAN folder.

Run the Preparations cell
Run the Preparations cell

Now we’ll just wait a minute or so.

Run “2. Upload Images” Cell and Upload Your Image

The next cell we run will make a button appear that we can click and then we can browse what image we want to use.

Screenshot with 2. Upload Images Cell
Upload Images

There’s another cell below this one that says OR you can use the demo image by running the following codes. We don’t want that, because it’s for demo purposes. It’s an image of Blake Lively.

Run “3. Inference” Cell to Use GFPGAN to Improve the Image

After you upload your image, we’ll run the cell under 3. Inference. This is the cell that will improve our image’s quality.

Run 3. Inference cell
Run the Inference cell

View / Download Your Final Image

After you’ve run this cell our image has been generated. If you haven’t noticed already, Google Colab has a file explorer on the left. Just click the folder icon.

You should then see the GFPGAN folder. You can find your final image in GFPGAN > results > restored_imgs. As you can see in our example I have a file called yennefer.png.

Google Colab File Browser
Google Colab File Browser

You can double click that image and it will load on the right of the screen, or you can right click and click Download to download it.

Since we already got our image, the next steps are optional.

Run “4. Visualize” Cell to See Side by Side Face Comparison (Optional)

With this cell we can get a close-up of the face in our photo to see a before / after comparison.

Screenshot of Google Colab Cropped Face Result Comparison
Cropped Face Result Comparison

Run Next Cell to Visualize The Whole Image Side by Side Comparison (Optional)

With the next cell we can see a before/after comparison of the whole image.

Screenshot of Google Colab Whole Image Result Comparison
Whole Image Result Comparison

Run “5. Download Results” Cell to Download All Images (Optional)

This cell will zip the results folder you see in the file browser on the left, and it will download it under the name of downloads.zip.

The archive will contain a few images:

  • results/cmp contains the cropped faces before/after side by side in a single image.
  • cropped_faces contains the cropped before face.
  • restored_faces contains the cropped after face.
  • restored_imgs contains the whole result image, upscaled and improved.

If you read what it says in the cell, it says zip -r download.zip results which means “create a .zip file with the results folder”. So you may not need to download this. You can just right click any image and click Download to download them individually.

Screenshot of Google Colab 5. Download Results Cell
Download Results

Conclusion

Well done! In this tutorial we used GFPGAN to fix or restored faces in photos, and to upscale the whole photo, in Google Colab. In our demo we used it to fix faces from AI generated images, but you can use it for old or damaged photos as well. If you encountered any issues feel free to leave a comment and we’ll get back to you as soon as possible.

Resources & Acknowledgements

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

0 Comments
Inline Feedbacks
View all comments
You May Also Like