LaMa inpainting, WebGPU-ready ONNX

LaMa ("Resolution-robust Large Mask Inpainting with Fourier Convolutions", Suvorov et al., WACV 2022) as a single fp32 ONNX graph that runs on onnxruntime-web's WebGPU execution provider. It is used by the on-device AI eraser of the ToolsMonk Photo Editor and Background Remover.

Why this build exists

The published LaMa ONNX exports run in the browser on WASM only. On WebGPU (onnxruntime-web 1.30) every run fails inside the Fourier unit ("Failed to run JSEP kernel"). This file is the same model with three numerically equivalent graph rewrites:

  1. constant folding at a fixed batch of 1, so the DFT matrices the export builds at run time become constants;
  2. every Einsum (ij,jk->ik, 216 nodes) rewritten as MatMul;
  3. every negative-step Slice (72 nodes) rewritten as Gather with constant reversed indices.

Maximum output difference against the source on a 512x512 test input: 0.00026 on the 0..255 scale. Measured in Chrome: ~1.7-2.2 s per 512x512 inpaint on WebGPU, against ~30 s on single-threaded WASM.

Inputs and outputs

  • image: float32 [1, 3, 512, 512], RGB in 0..1
  • mask: float32 [1, 1, 512, 512], 1 = area to fill, 0 = keep
  • output: float32 [1, 3, 512, 512], RGB in 0..255

Provenance and licence

  • Model: advimman/lama, Apache-2.0.
  • Source ONNX: Carve/LaMa-ONNX lama_fp32.onnx, Apache-2.0 (sha256 1faef5301d78db7dda502fe59966957ec4b79dd64e16f03ed96913c7a4eb68d6).
  • Conversion script: build-lama-webgpu.py in this repository (requires onnx, onnxruntime, numpy).

This derivative is distributed under the same Apache-2.0 licence. The rewrites change the graph's structure, not its weights.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support