GFPGAN Tutorial: Restore Old Faces with AI — Complete Step-by-Step Guide
From installation to API deployment — this tutorial walks through every step of restoring old faces with GFPGAN, including Docker and Python API.
GFPGAN Tutorial: Restore Old Faces with AI — Complete Guide
This hands-on tutorial walks you through installing GFPGAN, restoring old face photos, enhancing video face restoration, and deploying with Docker. Each step includes exact commands you can copy and paste.
🚀 Want to deploy GFPGAN yourself?
Docker configs, system requirements, and installation guides — all on one page.
View GFPGAN Tool Page →
Prerequisites
- Python 3.7+ / pip
- NVIDIA GPU 2GB+ VRAM (CPU slower)
- Docker optional for container deployment
Step 1: Install
git clone https://github.com/TencentARC/GFPGAN.git && cd GFPGAN
pip install basicsr facexlib && pip install -r requirements.txt
python setup.py develop
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models/
Step 2: Restore a Photo
python inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.3 -s 2
Step 3: Cropped Face Mode
python inference_gfpgan.py -i inputs/cropped_faces -o results -v 1.4 -s 2 --aligned
Step 4: Full Photo (Faces + Background)
pip install realesrgan
python inference_gfpgan.py -i inputs/ -o results/ -v 1.3 -s 2 --bg_upsampler realesrgan --bg_tile 400
Step 5: Docker Deploy
docker pull wpafbo79/gfpgan:latest
docker run -d --name gfpgan --gpus all -v ./inputs:/inputs -v ./outputs:/outputs wpafbo79/gfpgan:latest
docker exec gfpgan python inference_gfpgan.py -i /inputs -o /outputs -v 1.3 -s 2
Step 6: Python API
import cv2
from gfpgan import GFPGANer
restorer = GFPGANer(model_path="GFPGANv1.3.pth", upscale=2, arch="clean", channel_multiplier=2)
img = cv2.imread("photo.jpg", cv2.IMREAD_COLOR)
_, _, restored = restorer.enhance(img, has_aligned=False, paste_back=True)
cv2.imwrite("restored.jpg", restored)
Model Guide
| Model | Quality | Speed | For |
|---|---|---|---|
| v1.3 | ★★★★★ | ★★★☆☆ | Best quality |
| v1.2 | ★★★★☆ | ★★★★☆ | Good + fast |
| v1.4 --aligned | ★★★★★ | ★★★☆☆ | Cropped faces |
Troubleshooting
OOM Error
Use --bg_tile 200 or -s 1 for no upscale.
Face Not Detected
Crop faces manually and use --aligned mode.
Too Smooth
Use --weight 0.3 or try -v 1.2 model.
Slow on CPU
Use -s 1, cropped faces, or the Clean model variant.
API Wrapper
from flask import Flask, request, send_file
import cv2, tempfile
from gfpgan import GFPGANer
app = Flask(__name__)
r = GFPGANer(model_path="GFPGANv1.3.pth", upscale=2)
@app.route("/restore", methods=["POST"])
def restore():
f = request.files["image"]; t = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False)
f.save(t.name); img = cv2.imread(t.name); _, _, out = r.enhance(img, paste_back=True)
o = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False)
cv2.imwrite(o.name, out)
return send_file(o.name, mimetype="image/jpeg")
app.run(host="0.0.0.0", port=5000)
Conclusion
GFPGAN takes ~10 minutes to set up. For best results pair with Real-ESRGAN for complete photo restoration.
#face-restoration
#tutorial
#docker
#image-enhancement