LaMa (big-lama inpainting) (fastforks)
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.
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/advimman/lama at 786f5936b27f.
Author weight repos: https://huggingface.co/smartywu/big-lama.
Task: restoration. Tier: experimental. Outputs: image. Backends: portable, kernels.
Input: one RGB image. Output: the restored (upscaled) image, model.scale x the input size, RGB in [0, 1]. tile= runs large images in overlapping tiles (as ComfyUI).
Variants
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
big-lama@1 |
big-lama.ckpt | fccb7adffd53 |
Apache-2.0 | yes |
Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: LICENSE.
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).).
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
Input size
any H x W >= 16, padded to a multiple of 8
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): big-lama 3000x4000 (5.1 GiB peak allocated, 6.8 reserved)
Speed and memory
Restoration, synthetic, 512x512
| model | time (ms): original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|
big-lama |
38.0 | 26.0 | 21.2 | 1.8x | 1.2x | 239 / 286 | 219 / 242 | 219 / 284 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
big-lama |
0.52 | 0.31 | 0.65 | 0.33 | 0.27 | 0.12 |
torch.compile and TensorRT
| model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) |
|---|---|---|---|---|---|---|---|---|---|---|---|
big-lama |
512x512 | 26.0 ms | 23.4 ms | planned for 0.2.1 | 21.2 ms | 25.9 s | β | 219 / 242 | 312 / 342 | 219 / 284 | β |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
Accuracy
Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. 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).
Limitations
- 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.
Usage
from fastforks import restoration
model = restoration.load("big-lama") # mode="auto": the preferred backend from recorded measurements
result = model("photo.png") # tile=512 for large images
result.image # [3, sH, sW] float32 RGB in [0, 1], s = model.scale
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: big-lama.
Kernels backend
restoration.load("big-lama", mode="kernels") runs our CUDA kernels (cudnn_hacc). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.