Skip to content

How-ToGPU

How to Restore Old Photos Locally With CodeFormer on Your PC

CodeFormer is a free AI model that rebuilds blurry and faded faces in old photos, and it runs on your own graphics card so your family pictures stay private. Using the official GitHub README, we explain how to install it, restore whole photos, pick the right fidelity setting, and handle cropped faces, colourisation and video.

By , Systems & Technical Editor

5 min read

How to Restore Old Photos Locally With CodeFormer on Your PC

Faded school portraits, blurry wedding snaps and low-resolution scans of family albums are exactly what AI face restoration was built for. CodeFormer, from Nanyang Technological University's S-Lab, rebuilds damaged or blurry faces, and it can tidy up the rest of the photo too. It's free to download and runs on your own graphics card, so your family photos never leave your PC. This guide follows the official CodeFormer GitHub README.

What CodeFormer can and can't do

CodeFormer was presented at NeurIPS 2022 as a "blind face restoration" model. In plain English, it doesn't need to know how a photo was damaged. It recognises faces and predicts a cleaner, sharper version of each one. The README covers four jobs:

  • Whole-image enhancement – finds every face in a photo, restores it and pastes it back

  • Face restoration on cropped, aligned faces – for 512x512 face crops

  • Face colourisation – adds colour to black-and-white or faded face crops

  • Face inpainting – fills in parts of a face you've painted over in white

Be realistic about what that means. CodeFormer is a face model. On its own it doesn't remove scratches, creases or stains from the rest of the picture, although it can hand the background to Real-ESRGAN for upscaling. For badly scratched prints, Microsoft's Bringing Old Photos Back to Life project is designed to detect and repair scratches. And because the model predicts detail it can't actually see, a restored face is a best guess, not a recovered original. Keep your original scan.

Check the licence first

CodeFormer uses the NTU S-Lab License 1.0, which only allows redistribution and use for non-commercial purposes. Restoring your own family photos is fine. If you want to sell a restoration service or use it in paid client work, you'll need permission from the authors, or a different model. GFPGAN, for example, uses the Apache 2.0 licence.

The README also warns that only the demos on Hugging Face, Replicate and OpenXLab are maintained by the authors. It names CodeFormer.net, CodeFormer.cn and CodeFormerAI.com as non-official websites that use the models without the authors' permission. Running it locally avoids that problem completely.

What you need

The README lists PyTorch 1.7.1 or newer, CUDA 10.1 or newer and the packages in its requirements file. CUDA means an Nvidia graphics card. The developers don't publish a minimum VRAM figure. Face restoration models are much smaller than the image generators and large language models we usually cover, so as our suggestion rather than an official requirement, an 8GB card such as the ASUS RTX 5060 8GB Dual OC is a sensible starting point. If you also want to run image generators, a 12GB card like the ASUS RTX 3060 12GB Dual Gaming OC V2 gives you more room. Our guide to how much VRAM you need explains the trade-offs.

The README's commands use Anaconda (conda) and git. They work in a Linux terminal, and the README's video section mentions Windows and Mac users, but if you run into build problems on Windows, WSL2 with Ubuntu is the easiest fallback. Our guide to setting up WSL2 for GPU-accelerated local AI covers that.

Step 1: Scan your photos properly

The better the input, the less the AI has to guess. Scan prints on a flatbed scanner rather than photographing them with a phone, save them as PNG or high-quality JPEG files, and keep the untouched scans in a separate folder. Crop out the album page or scanner lid, but don't sharpen or denoise the scans first. Let the model work from the original detail.

Step 2: Install CodeFormer

Open a terminal and run the README's commands:

git clone https://github.com/sczhou/CodeFormer
cd CodeFormer
conda create -n codeformer python=3.8 -y
conda activate codeformer
pip3 install -r requirements.txt
python basicsr/setup.py develop

The README also lists an optional conda install -c conda-forge dlib step. You only need it for the dlib face detector or for cropping faces with dlib. If your PyTorch install doesn't detect your graphics card, install a CUDA build of PyTorch for your driver, then try again.

Step 3: Download the models

CodeFormer needs its face detection models and its own restoration weights. The README provides a script for both:

python scripts/download_pretrained_models.py facelib
python scripts/download_pretrained_models.py CodeFormer

Add python scripts/download_pretrained_models.py dlib if you want the dlib detector. If the script fails, the README links to the same files on the project's GitHub Releases page. They go in the weights/facelib and weights/CodeFormer folders.

Step 4: Restore a whole photo

For a normal scanned photo with one or more faces in it, use the whole-image command and point it at a file or folder:

python inference_codeformer.py -w 0.7 --input_path inputs/my_scans

Results are saved in the results folder. Two optional flags are worth trying:

  • --bg_upsampler realesrgan enhances the background with Real-ESRGAN

  • --face_upsample upsamples the restored faces again with Real-ESRGAN

Step 5: Choose the right fidelity weight

The -w setting is CodeFormer's most important control. It runs from 0 to 1. The README says lower values tend to give higher-quality results, while higher values give results that are more faithful to the input. In practice that's a trade-off between a cleaner face and one that still looks like the person in the photo.

We'd start at the README's 0.7 for family photos, where likeness matters most. Then run the same photo at a lower value such as 0.5 and compare the two. If a relative's face starts to look like a stranger's, move the value back up towards 1.

Optional: cropped faces, colour and inpainting

For close-up portraits, you can work on cropped, aligned faces instead. The README's scripts/crop_align_face.py script creates 512x512 crops (it uses dlib). Then run:

python inference_codeformer.py -w 0.5 --has_aligned --input_path inputs/cropped_faces

The same crops work with inference_colorization.py, which colourises black-and-white or faded faces, and inference_inpainting.py, which fills in areas you've masked with a white brush in an image editor. Both work on face crops only, not whole photos.

Restoring old video

CodeFormer also accepts .mp4, .mov and .avi clips. Install ffmpeg (conda install -c conda-forge ffmpeg), then use the README's video command:

python inference_codeformer.py --bg_upsampler realesrgan --face_upsample -w 1.0 --input_path old_clip.mp4

For general video upscaling rather than faces, see our guide to upscaling videos locally with Video2X.

Troubleshooting

  • Hair looks odd around the face: the README notes that whole-image mode blends the face back into the background, which can affect hair texture at the edges. Try the cropped-face workflow for portraits.

  • The face doesn't look like the person: raise -w towards 1.

  • Out of memory errors: process one image at a time, or see our guide to fixing CUDA out of memory errors.

  • You'd rather not use a terminal: CodeFormer's README lists third-party integrations, including the node-based chaiNNer app and AUTOMATIC1111's Stable Diffusion WebUI. These aren't maintained by the CodeFormer authors, so check each project's own instructions.

The bottom line

CodeFormer is one of the best free ways to rescue blurry and faded faces in old family photos, and running it locally keeps your pictures private. Install it from the official GitHub repository, start with a fidelity weight of 0.7 to keep likenesses intact, and add Real-ESRGAN for the background. Remember that its licence is non-commercial only, and always keep your original scans.

In this article

Sources

  1. 01S-Lab, Nanyang Technological University, CodeFormer GitHub repository and README
  2. 02S-Lab, CodeFormer licence (NTU S-Lab License 1.0)
  3. 03Xintao Wang, Real-ESRGAN GitHub repository
  4. 04Microsoft, Bringing Old Photos Back to Life GitHub repository

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

Best Local AI Image Captioning Tools in 2026

Best Picks

Best Local AI Image Captioning Tools in 2026

You don't need a paid cloud service to caption images for LoRA training, alt text or photo archives. We pick the best free AI captioning and tagging tools you can run on your own PC in 2026, from the TagGUI desktop app to Florence-2, JoyCaption, WD Tagger v3 and the kohya-ss tagging script, with hardware and licence notes.

Hannah Vance5 min

JoyCaption vs Florence-2: Which Local AI Image Captioner Should You Use?

Versus

JoyCaption vs Florence-2: Which Local AI Image Captioner Should You Use?

JoyCaption and Microsoft's Florence-2 are two of the most popular free AI models for captioning images on your own PC. We compare their size, video memory needs, caption styles, extra features and licences, so you can pick the right one for LoRA training datasets, alt text or a big photo archive.

Callum Reid5 min

How to Auto-Caption a LoRA Training Dataset Locally With TagGUI

How-To

How to Auto-Caption a LoRA Training Dataset Locally With TagGUI

Writing captions for every image in a LoRA training set by hand is slow. TagGUI is a free desktop app that runs AI captioning models such as Florence-2, WD Tagger and JoyCaption on your own PC and writes the text files for you. Using its official README, we explain how to install it, run batch captioning, steer the output and clean up the results.

Marcus Thorne6 min

Cyber Monday 2026 UK: What to Expect for PC Parts After Black Friday

News

Cyber Monday 2026 UK: What to Expect for PC Parts After Black Friday

Cyber Monday is on 30 November 2026, and for UK PC parts it's the last day of the same sale rather than a new one. VantaSpec counted 402 of 1,413 recent price cuts as genuine 90-day lows on 28 November. Here's what to expect on Monday, when to buy now or wait, and how your return rights work.

Eleanor Shaw3 min