Restores and upscales low-resolution or distant faces before they're passed to face recognition, using CodeFormer. Chosen over GFPGAN and Real-ESRGAN alone for better identity preservation on degraded faces — important since the goal is to help recognition match a face correctly, not just make an image look sharper.
This is a preprocessing step in the larger pipeline: it runs when a detected face is too low-quality for face recognition to confidently match, restoring it before a second recognition attempt.
| Before (low-res input) | After (CodeFormer restored) |
|---|---|
![]() |
![]() |
- Face detected (by the face recognition module) but too low-resolution/distant to match confidently
- CodeFormer restores and upsamples the face region (fidelity vs. quality controlled by the
-wweight parameter) - Restored face is re-attempted against the recognition step
.
├── superres_fr.ipynb # Full Colab notebook: setup, weights, inference, before/after comparison
├── assets/ # Demo before/after images
├── LICENSE
└── .gitignore
Run the notebook top to bottom. It handles:
- Environment setup — installs
basicsr/facexlib, with a compatibility shim for a broken torchvision import inbasicsr(must run beforebasicsris imported) - Cloning CodeFormer and installing its requirements
- Downloading model weights — CodeFormer, face detection, face parsing, and Real-ESRGAN (background upsampling), with an automatic fallback to a mirror if the primary Real-ESRGAN download comes back corrupted
- A
torch.loadcompatibility patch — newer PyTorch defaults toweights_only=True, which breaks basicsr's checkpoint loader; this patches it safely (checks if already patched before touching the file) - Inference on a test image, with a before/after visual comparison
Note on CodeFormer itself: unlike the anti-spoofing module, CodeFormer's weights (~400MB+ combined) are not vendored into this repo — that's too large for a normal Git repo without Git LFS. The notebook clones CodeFormer and downloads weights fresh each run instead, from the actively-maintained official repo.
basicsrimporting a torchvision internal (functional_tensor) that no longer exists in current torchvision — fixed with a module shimtorch.loaddefaulting toweights_only=Truein newer PyTorch, breaking basicsr's Real-ESRGAN loader — patched in-place- Unreliable Real-ESRGAN weight download from the official release URL — automatic corrupted-file detection and fallback to a mirror
CodeFormer · basicsr · facexlib · Real-ESRGAN · PyTorch · OpenCV · Google Colab (GPU runtime)

