Inpaint (using LaMa + Refinement)
Object removal in seconds, no diffusion in sight — just don't trip the px_budget
- inpaint_model
- image
- mask
- IMAGE
You've got a photo with a person, a watermark, or a stray power line in it, and you want it gone - not "softened," not "regenerated from a sentence." That's this node's entire job, and it does it in seconds instead of the minutes a 12B diffusion model would burn re-emitting the whole frame.
LaMa is the old-school CNN inpainter (Samsung Research, 2021) the community never quite stopped using for cleanup. It's not a diffusion model: no denoising steps, no prompt, no VAE round-trip - just one fast forward pass that fills the masked hole with plausible texture. Its historical weakness is that on big holes that texture doesn't always connect to the surrounding structure. The "Refinement" half of this pack exists to fix that, and it's what makes the node worth reaching for over the other LaMa wrappers.
What the refiner actually does
The node builds a coarse-to-fine pyramid of your image - blurred and downscaled by half, up to five levels with a floor of 512px on the short side. LaMa runs at the smallest scale first. Then at each finer scale, instead of just running LaMa once and hoping, it keeps LaMa's internal feature maps, turns on gradient tracking, and optimizes those features with Adam for about 15 iterations so the output agrees with both the known pixels and the coarser scale below it. Coarse structure first, detail layered on top. That's the refinement, ported from geomagical's lama-with-refiner research code.
The payoff: most of LaMa's speed with much better coherence on large holes than a bare LaMa pass. And because the code composites mask * inpainted + (1 - mask) * original, every pixel outside your mask comes out bit-identical - the exact property the KB says is the whole remaining reason to use masked inpainting in 2026. Nothing outside the mask moves, not even through a VAE.
The inputs that matter
Most of the interface is boring, which is good. inpaint_model takes the output of the sibling Load Inpaint LaMa Model node. image and mask are your photo and a single-channel mask where white/1 marks the region to replace - they must be the same dimensions or the node throws. seed is exposed for reproducibility, but LaMa is deterministic, so changing it won't reshuffle your result.
The one that bites is px_budget: the max pixel count the refiner will process, default 800,000. Here's the trap - a plain 1024×1024 image is 1,048,576 pixels, over the default. When that happens the node silently downscales the image to fit the budget, refines at that size, and hands you back a smaller image. No warning, no upscale-back. For 1024×1024 work, set it to at least 1,100,000. Anything bigger is a VRAM trade: the refiner keeps autograd graphs alive through 15 optimizer steps per scale.
The single output is the composited IMAGE, wired straight into Save Image.
Install
ComfyUI Manager: search lama_with_refiner. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/fplu/comfyui_lama_with_refiner.git
Then grab big-lama.pt (~200 MB) from any mirror in the README and put it in ComfyUI/models/inpaint/ (create the folder if it's not there). One gotcha: the pack declares no requirements.txt, so if the node shows IMPORT FAILED, it's usually kornia missing from your ComfyUI venv - pip install kornia fixes it.
Where people get burned
- Silent downscale - the
px_budgettrap above. The single most confusing behavior in this pack. - OOM on big images - the classic LaMa-in-ComfyUI complaint, and the refiner makes it worse than a plain LaMa pass. If a 12 GB card chokes, crop around the mask first with an Inpaint Crop and Stitch pattern, or drop
px_budgetand accept lower output res. - Wrong expectations - this is a texture-filling CNN, not a generator. It removes objects and cleans up. It will not invent a new object that "belongs" in the hole; for that you want a diffusion inpaint or an edit model running inside the mask.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| inpaint_model | INPAINT_LAMA_MODEL | — | |
| image | IMAGE | — | |
| mask | MASK | — | |
| seed | INT | 00–18446744073709550000 | — |
| px_budget | INT | 80000010000–10000000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |