Skip to content
WebAI

Erasing a watermark and erasing a passer-by both end up at one 26.8 MiB checkpoint

The watermark, object-removal and inpainting pages share one set of brush controls, and their real weights mostly come down to the same 26.8 MiB MI-GAN ONNX. The exception is the video HD pass, which genuinely loads the 198 MiB LaMa checkpoint.

A brush from 8 to 96 pixels, edge feather from 0 to 24, and three fill methods (context aware, blur, clone nearby). All three pages use these same controls. Four different models in the catalogue, and most of them end up at the same 26.8 MiB ONNX graph once real weights are wired up.

PageCardListed sizeWhat runs
Watermark removalMI-GAN~26.8 MiBMI-GAN ONNX (uint8)
Watermark removalLaMa FP32~198 MiB · fp32MI-GAN, with an asterisk in the result bar
Object removalImage object eraserNot measuredMI-GAN ONNX (uint8)
InpaintingSDXL InpaintNot measured (historic estimate ~3.8 GB)MI-GAN, with an asterisk
Cards on the three pages and the checkpoints actually loaded

On the single-image watermark page LaMa is marked as a substitute. The weights table gives the reason: that 198 MiB fp32 ONNX graph cannot even create a session on the wasm execution provider, so the page falls back to the 26.8 MiB MI-GAN. The HD pass on the video watermark page really loads lama_fp32.onnx from Carve/LaMa-ONNX, wasm only, because WebGPU deadlocks on it. Inference is roughly seven times slower than MI-GAN and buys noticeably better reconstruction on large watermarks and structural edges.

Cropping the mask

miganInpaint() first finds the bounding box of pixels whose alpha exceeds 0.35, then pads it with at least 48 pixels or 0.8 times the side length, and crops a centred square around it. An empty mask returns the original image immediately, with no download. The crop is squeezed to 512x512 and split into a CHW uint8 image tensor plus a mask of the same size. A mask value of 255 keeps the pixel, and any pixel with alpha above 0.35 becomes 0 for the model to rebuild. The output has to be 1,3,512,512 or the call throws. Sessions are cached in a Map keyed by the weights URL, and weight files go into the ai-demos-onnx-v1 Cache Storage bucket, so a second run downloads nothing.

The MI-GAN input contract
const imageTensor = new ort.Tensor('uint8', img, [1, 3, SIZE, SIZE]);
const maskTensor = new ort.Tensor('uint8', mask, [1, 1, SIZE, SIZE]);
// 255 = keep the pixel, 0 = let the model rebuild it
const result = await session.run({ image: imageTensor, mask: maskTensor });
if (result.result.dims.join(',') !== '1,3,512,512') throw new Error('Unexpected output shape');

The generated patch is composited back at the original resolution, with a linear blend driven by featherMask(). That function scans twice to measure each painted pixel distance to the unpainted region, then divides by the slider value to make a 0 to 1 ramp. A stroke that is too faint, with alpha below 0.35, never enters the mask and leaves a pale ghost behind. Painting the watermark together with a wide band of background does not work either. Once that square is squeezed into 512x512, the strokes that actually need filling occupy only a small part of it, and the edges turn mushy. Tracing just the watermark strokes and leaving surrounding pixels as context holds up much better.

Single-threaded sessions

Custom ONNX graphs like this have no matching Transformers.js pipeline, so we create an onnxruntime-web/wasm session directly. The hosting platform sends no COOP or COEP headers, crossOriginIsolated is false, SharedArrayBuffer is unavailable, and numThreads has to be 1. graphOptimizationLevel is disabled too, since the optimiser aborts on large exported graphs. On all three pages the wait is mostly the first download and session creation. The result bar reports the bytes downloaded on that run.

SDXL Inpaint is listed at about 3.8 GB with no browser-loadable weights, and the page says that MI-GAN runs in its place. The text-to-image page marks the whole category as browser-infeasible.

All posts →

← Back to all posts