LaMa (big-lama inpainting)
LaMa big-lama (Suvorov et al., Samsung AI, WACV 2022): fills the masked hole of an image (object removal) with a fast-Fourier-convolution network trained on scene photos. Apache-2.0 code and weights; the Places365 training images are for research use only (see the card).
experimental Fork of advimman/lama@786f593 · backends: portable, kernels
- Paper Resolution-robust Large Mask Inpainting with Fourier Convolutions WACV 2022 · first released 15 Sept 2021
Checkpoint big-lama
Paper 2021 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import restoration
model = restoration.load("big-lama") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend # what ran: mode, device, dtype, kernels fastforks bench big-lama Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 512x512 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16.half() on 1 modules, fp16 inputs; advimman/lama@786f5936b27f FFCResNetGenerator, predict.py padding / masking / paste-back | fp16 | 38.0 | – | 239 MiB/286 MiB | 0.4 | 0.07 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 26.0 | 1.5× | 219 MiB/242 MiB | 0.8 | 0.25 |
| Kernels | fp16 | 21.2 | 1.8× | 219 MiB/284 MiB | 0.7 | 0.15 |
| Portable + torch.compile | 23.4 | 1.6× | 312 MiB/342 MiB | 26 (build) | – | |
| TensorRT fp16 | fp16 | 33.9 | 1.1× | 268 MiBenginenot comparable | 110 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-14 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 334 | 2,096 MiB process | – | 512x512 |
| Portable | fp16 | 214 | 1,679 MiB process | matches | 512x512 | |
| Portable | fp32 | 241 | 1,797 MiB process | matches | 512x512 | |
| Kernels | fp16 | not implemented | – | 512x512 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0 LICENSE
- Weights
- Apache-2.0 source
- Training data
-
- Places365-Challenge (8 M scene images, 365 categories) noncommercial, non-commercial
Our reading of the licences, not legal advice.
Weights
big-lama.ckpt 410 MB· inside a 381 MB archive· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download big-lama).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
DIV2K validation
25 centre crops with two masks each, masked RGB PSNR (dB)
| Run | dtype | psnr ↑ | Δ psnr vs fp32 original | masks | ms / mask |
|---|---|---|---|---|---|
| Original fp32 | fp32 | 17.8956 | reference | 50 | – |
| Original fp16 | not measured | ||||
| Portable fp32 | fp32 | 17.8950 | −0.0006 | 50 | – |
| Portable | fp16 | 17.8946 | −0.0010 | 50 | – |
| Kernels | not measured | ||||
DIV2K validation HR images and the official bicubic LR images (x4 or x2, the model's scale), one pass without tiles; PSNR and SSIM (Gaussian 11 x 11, sigma 1.5) on the Y channel (BT.601) of the output rounded to uint8, `scale` px border cropped, averaged over the images. Real-ESRGAN is trained for real-world degradations, not bicubic, so its PSNR is low: the numbers compare our modes with the original, not with PSNR-oriented upscalers. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-17; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks a7fe3731, 2026-11-17.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 1e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.002 and p99 <= 0.01 (absolute error of the output image).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.00001 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.002 | 0.00022 |
| GPU default dtypes, p99 |diff| | ≤ 0.01 | 0.00403 |
Recorded for big-lama on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14, with these kernels: cudnn_hacc
Details
LaMa (Suvorov et al., WACV 2022): resolution-robust large-mask inpainting with fast Fourier convolutions: an encoder of three strided convs, 18 FFC residual blocks whose global branch convolves in the frequency domain (an image-wide receptive field from the first block) and a transposed-conv decoder. big-lama (51 M parameters) is the authors' best model, trained on Places365 at 256 x 256 and works at higher resolutions. Pass `mask=` (nonzero = the region to fill); the rest of the image is kept unchanged.
- Input / output
- Input: one RGB image. Output: the restored (upscaled) image,
model.scalex the input size, RGB in [0, 1].What the numbers mean, and which models need the camera focal length
tile=runs large images in overlapping tiles (as ComfyUI). - Input size
- any H x W >= 16, padded to a multiple of 8; tested up to 3000x4000 (5,193 MiB allocated)
- Options
cuda_graphs=true
- Outputs
image- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Limitations
- No accuracy measurement: inpainting is scored on Places / CelebA-HQ with the authors' random masks, which are not part of the evaluation data here; tiers are compared by output parity and speed only.
- Fills the masked region from the surrounding image; it does not take a text prompt. The authors' refinement step (`refine=True`, an iterative multi-scale optimisation) is not implemented.
- Any nonzero mask pixel is a hole (upstream binarises with `mask > 0`): anti-aliased or JPEG masks grow; threshold them first.
Full reference, generated from the repository
LaMa big-lama (Suvorov et al., Samsung AI, WACV 2022): fills the masked hole of an image (object removal) with a fast-Fourier-convolution network trained on scene photos. Apache-2.0 code and weights; the Places365 training images are for research use only (see the card).
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
big-lama | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 38.0 26.0 21.2 23.4 33.9 | 239 / 286 219 / 242 219 / 284 312 / 342 386 / 406 |
Details
- Original code: https://github.com/advimman/lama at
786f5936b27f - Code licence: Apache-2.0 (permissive); files:
LICENSE - Weights licence: Apache-2.0
- Licence evidence: https://github.com/advimman/lama/blob/786f5936b27fb3dacd2b1ad799e4de968ea697e7/LICENSE ; https://github.com/advimman/lama/blob/786f5936b27fb3dacd2b1ad799e4de968ea697e7/README.md ; https://huggingface.co/smartywu/big-lama/blob/05cb2be7f8dbe6ca7c6e78f4fc827a4b2baaa4a9/README.md
- Training data: Places365-Challenge (8 M scene images, 365 categories) (big-lama: Places365-Challenge (about 4.5 M images used) with LaMa's random wide / box masks, 256 x 256 crops (paper Sec. 4 and README).)
- Options:
cuda_graphs= True (speed only) - Kernel libraries:
cudnn_hacc - Variants:
big-lama - Outputs: image
- Input size: any H x W >= 16, padded to a multiple of 8
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
big-lama3000x4000 (5.1 GiB peak allocated, 6.8 reserved) big-lama512x512, first call: portable + torch.compile 26 s (cold Inductor cache), TensorRT fp16 110 s (ONNX + engine).big-lamaoriginal 512x512: .half() on 1 modules, fp16 inputs; advimman/lama@786f5936b27f FFCResNetGenerator, predict.py padding / masking / paste-backbig-lamaload / first call: original 0.52 s / 0.327 s, portable 0.81 s / 0.246 s, kernels 0.72 s / 0.15 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
DIV2K validation HR images and the official bicubic LR images (x4 or x2, the model's scale), one pass without tiles; PSNR and SSIM (Gaussian 11 x 11, sigma 1.5) on the Y channel (BT.601) of the output rounded to uint8, scale px border cropped, averaged over the images. Real-ESRGAN is trained for real-world degradations, not bicubic, so its PSNR is low: the numbers compare our modes with the original, not with PSNR-oriented upscalers. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | portable | portable fp32 | TensorRT | note |
|---|---|---|---|---|---|---|
big-lama | DIV2K validation, 25 centre crops with two masks each, masked RGB PSNR (dB) | 17.8956 | 17.8946 | 17.8950 | 17.8854 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks a7fe3731, 2026-11-17.
Parity
CPU, float32: max |diff| <= 1e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.002 and p99 <= 0.01 (absolute error of the output image).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
big-lama | 0.00022 / 0.00403 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
Limitations
- No accuracy measurement: inpainting is scored on Places / CelebA-HQ with the authors' random masks, which are not part of the evaluation data here; tiers are compared by output parity and speed only.
- Fills the masked region from the surrounding image; it does not take a text prompt. The authors' refinement step (
refine=True, an iterative multi-scale optimisation) is not implemented. - Any nonzero mask pixel is a hole (upstream binarises with
mask > 0): anti-aliased or JPEG masks grow; threshold them first.
Example output
No example rendered for this checkpoint yet.