Takes a source Image and a Mask (or second Image channel) and reconstructs the masked region with learned content; supports LaMa (fast, CPU/GPU), SD2 (text-guided, GPU) and FLUX.2 klein (edits the masked region after a prompt and a reference picture, for example bare hands into gloved hands, GPU) backbones. Prefer Inpaint Image (OpenCV) for small scratches.
Typical backends
Object removal from a file — source plus mask inpainted and pushed to an HTTP sink.
Dewatermark pipeline — a thresholded, morphology-cleaned mask drives the fill.
Threshold mask carrier — the Mask input arm fed directly by a thresholded hole map.
Training-data edit — a segmenter's hand mask drives a FLUX.2 klein edit that puts the reference glove on every bare hand, leaving the rest of the frame untouched.
HTTP-sourced image inpainting with HTTP output.
Caveats
- CostPPL_GENERATION_METRICS strict JSON v4 is printed to component stdout and captured in deployment logs, the Python API logging channel. A startup record is emitted when loading finishes (status ready), even with no input, or on startup failure; each job emits a record including on failure. Envelope fields: schema_version, component, worker_id, job_index (null for startup; increasing per worker for jobs), phase (startup/job), worker_started_unix_ns, started_unix_ns, finished_unix_ns. recipe: model, checkpoints (loaded artifact role to hf:commit or sha256:file/tree identity), steps, width, height (working grid), frames, guidance, precision, device, cpu_offload, vae_tiling, fps, inputs, seed, rng_state_sha256, options (component-specific settings). inputs maps roles to descriptors: text has kind=text, sha256 of exact UTF-8 bytes passed to the model, and length in Unicode codepoints; absent text has null sha256/length. Pixel descriptors have kind=pixels, sha256, shape and dtype, using the same shape/dtype-prefixed digest below. The pixel roles are image, the source picture, mask, the logical boolean hole mask, and reference for flux2_klein; the text roles are prompt and negative_prompt, recorded only for the backbones that use them. Unused inputs are omitted. seed is the explicit initializer, null when absent; negative values retain the component random-mode convention. Global stochastic draws also record CPU/CUDA RNG-state byte digests in rng_state_sha256 (null when unavailable), without advancing them; a startup initializer alone does not pin every later draw. sources: list of pixels_sha256 and position (the received picture's position when its PictureIdentity is wired, else null). timing_s: startup, model_load, total, encode, denoise, decode, in synchronized wall seconds. Startup includes imports, configuration and loading; job total excludes startup and includes hot loading. Stage/load times are diagnostic subsets, never additive billing. Denoise times model forwards and scheduler steps; encode/decode time prompt and VAE encoding or decoding. LaMa runs no diffusion pipeline, so its stage times are zero. memory: gpu_allocated_peak_bytes, gpu_reserved_peak_bytes, gpu_name, host_rss_peak_bytes, host_sample_interval_ms (10 ms sampled process RSS). Peaks are scoped to loading or a job; GPU peaks cover the PyTorch allocator, excluding driver/external allocations. Unavailable probes are null. result: status, error_type (class only), output_count, generated_count, output_bytes, duration_s, outputs. Each outputs entry contains worker_id, job_index, zero-based sequence, pixels_sha256, position, generated, width, height, bytes. Bytes are raw emitted pixels, not compressed files. The digest is SHA-256 of sorted-key JSON {"shape":[height,width,3],"dtype":"uint8"} serialized with Python json.dumps(sort_keys=True) using its default comma-space and colon-space separators, a NUL byte, then decoded RGB bytes, matching ClipPosition picture digests. A picture that cannot be decoded to RGB fails the job, so a digest is never null; sinks must hash decoded pixels before lossy re-encoding. A position is clip_name, clip_sha256, frame_index, made_id, crop_id and position_ns of the PictureIdentity emitted with the picture, so it names the picture key a dataset shard saves the picture under; made_id and crop_id are each empty or a lowercase UUIDv4, and no generated_index is printed. It is null when no PictureIdentity is emitted. The attempt key is (worker_id, job_index); its output key adds sequence. Every output entry repeats this key. Positions and digests link an attempt to saved pictures; both can repeat for identical deterministic jobs and do not identify attempts. The backend must retain the association of each sink/save decision with the attempt/output key to attribute duplicate acceptance or rejection; content equality alone cannot recover it. Measuring changes no emitted position or output pixel. Status: ready (startup), generated, passthrough or failed. Passthrough is a job whose picture is empty or whose mask marks no pixel; the source is emitted unchanged and counts zero generated pictures. Each job emits one picture, a separate still with null duration. Usable, rejected, accepted and audited counts are decided downstream by the sink or review, not by the generator; the backend attributes those decisions through the output join keys, and no usable count is fabricated. The Python worker API has no documented stop hook: hard termination cannot emit a final summary. The backend must use deployment/vertex log context and actual lease reservations to account for startup, inter-job and post-job idle, shutdown and interruption capacity. No prompts or credentials are logged. Live tests assert startup before input, real GPU timings/peaks, output joins and cold/warm successful samples with matching configured recipe and input digests, retained as PPL_GENERATION_BASELINE in lease verifier stdout. Stochastic draws retain separate RNG-state digests; they are repeat samples, not claims of identical noise. Baselines are recorded when GPU tests run; no timing or PLC is inferred from offline fake pipelines.
- I/O contractInput 2 is an optional
PictureIdentity stream; the mask stays on input 1. Unwired, ordinary inpainting emits images and no position messages. Wired, each picture requires one valid position or fails. New pictures retain source provenance and pass, mint made_id, clear crop_id and retain any incoming sequence_id and sequence_index; no-ops preserve all position fields. Dataset graphs must carry paired picture and position streams along every path; this editor never invents provenance. For flux2_klein, input 3 holds the position of the picture bound to reference and is required alongside source position input 2 whenever provenance is wired; missing either fails. LaMa and sd2 use only source input 2; masks control the region and are not photographic parents. Known ancestry is an ordered set of at most 64 complete picture keys with source times: all immediate parents in input order, then the history of each parent in that order, deduplicated by key. Shared history is retained once; conflicting times, invalid keys, self references or overflow fail. Replay and no-ops preserve the set. New pictures include every contributing picture parent; the primary clip remains the source root. Records persist the set as a flat derived_from array, never a fabricated chain. - Hard constraintThe mask must match the source's width and height exactly. A mask with no set pixels is a no-op and the source is returned unchanged; an empty (zero-size) source
Image likewise passes through. Every input emits exactly one image. - I/O contractThe hole specification is a
Mask carrier (any set pixel is a hole) or a second Image channel reduced to grayscale (any non-zero pixel is a hole). Dilate the mask a few pixels past the object so its outline is fully covered. - I/O contractLaMa pads the image and mask to a multiple of eight internally and crops the result back; the output always matches the input resolution exactly.
- Parameter interactionLaMa ignores
prompt, steps, guidance, size and seed; it runs one deterministic forward pass at source size. Diffusion backbones use these parameters for their working recipe, then restore source dimensions. - Parameter interactionUnder
model `sd2` or `flux2_klein`, fix seed to a non-negative value for a reproducible fill; the diffusion backbones produce a different result per call otherwise. - Hard constraint
model `flux2_klein` needs two file slots bound: flux_snapshot, a FLUX.2 klein diffusers snapshot (model_index.json with scheduler, tokenizer, text_encoder, vae and transformer folders), and reference, the picture of what the masked region should look like. The worker refuses to start without either. `lama` and `sd2` load the model file slot instead and refuse to start without it. - I/O contractUnder
model `flux2_klein` the mask is grown by mask_dilate_px and only that grown region is edited; the edit fades in over mask_feather_px pixels inside its edge. Every pixel outside the grown mask is the source's value, so labels of everything else in the frame stay true. Keep mask_feather_px at or below mask_dilate_px so the marked object itself is fully replaced. - I/O contractUnder
model `flux2_klein` the model works on a square window around the grown mask, twice its size where the frame allows. Unset size scales this crop to about one megapixel; an override changes its working pixel budget to the chosen side squared. The edit is scaled back and pasted into the same window. - Parameter interactionScalar automatic sentinels are 18446744073709551615 for steps and 1.7976931348623157e308 for guidance; all other values override. Automatic
steps, guidance and size resolve per backbone: SD2 retains 30 steps, scale 7.5 and 512-square work; distilled FLUX.2 klein uses 4 steps, scale 1.0 and a 1024-square pixel budget. The snapshot's is_distilled metadata distinguishes undistilled klein, which uses 50 steps and scale 4.0. Explicit values override each setting independently, including scale zero; LaMa ignores all three. Distilled klein ignores classifier-free scaling. prompt is encoded once at start-up, so changing it needs a redeploy. - CompatibilityRecipes follow the FLUX.2 klein [distilled model card](https://huggingface.co/black-forest-labs/FLUX.2-klein-4B) and [base model card](https://huggingface.co/black-forest-labs/FLUX.2-klein-base-4B). SD2's [original card mirror](https://huggingface.co/sd2-community/stable-diffusion-2-inpainting) identifies the 512-base checkpoint but gives no numeric step recommendation, so its existing step count is retained. Each pipeline keeps the bound snapshot's scheduler unchanged: FlowMatch Euler for klein, PNDM for the original SD2 snapshot.
- I/O contractAll backbones preserve source resolution and colour space. LaMa and SD2 copy original native pixel bytes outside the supplied mask; klein copies them outside its grown mask. SD2 resizes only the edit window around the mask to its working pixel budget and pastes that crop back under the mask.
- CompatibilityStep and guidance parameters retain their released scalar types and step refinement. Automatic sentinels change their declared defaults; the platform currently drops stored bindings on any default change during a component-version upgrade. This still requires a platform migration fix; a backend pinned to its existing release is unaffected.
- AccuracyThe live test runs the default four-step klein recipe, then the previous 30-step / 7.5 recipe sequentially with identical pinned source, reference, prompt, mask and seed 7. Masked RGB mean absolute error against the previous result must be at most 25.5; both edits must differ from the masked source by more than 20. Source, mask, both outputs, difference, timings and scores remain in a directory per lease under tests/generation-comparison, including on failure. Inspect glove anatomy, reference appearance and seams; the pixel gate does not establish downstream detector quality.
- CostEvery backbone loads its weights from a bound file with no runtime download — the big-lama TorchScript checkpoint (~196 MB) for LaMa, the multi-gigabyte Stable Diffusion 2 inpainting snapshot for sd2, or the ~16 GB FLUX.2 klein 4B snapshot for flux2_klein. Allow a generous startup budget on a cold deployment.
- CostUnder
model `flux2_klein` the 4B checkpoint keeps its transformer and VAE on the GPU in bfloat16 and releases its text encoder after start-up. Measured on a 20 GB RTX 4000 SFF Ada beside a SAM 3 segmenter: a 4-step edit of one window took 15 to 20 s, and the card peaked at 19.5 GiB used during an edit. Plan for a GPU with 16 GB free for this backbone alone. - Hard constraintA CUDA request through
device fails at startup when CUDA is unavailable; CPU is used only when explicitly selected. Large inputs can exhaust memory, and synchronous inference holds this worker until the result is ready. - CompatibilityLaMa weights are Apache-2.0; FLUX.2 klein 4B is Apache-2.0; Stable Diffusion 2 inpainting is CreativeML Open RAIL++-M — review it before deploying
model `sd2` commercially.