LPIPSPipe
LPIPSPipe is registered as lpips-pipe and implemented in src/autopipeline/components/modules/lpips_pipe.py.
It is the framework's perceptual-distance module for full-image or region-limited comparisons.
Class
Overview
Registry Entry
| Field | Value |
|---|---|
| Registry key | lpips-pipe |
| Class | LPIPSPipe |
| Main mixins | LPIPSMixin, MaskProcessor |
| Return type | float |
Constructor
Constructor
LPIPSPipe(**kwargs)
Supported init kwargs
| Key | Required | Default | Meaning |
|---|---|---|---|
device | No | auto | Torch device for LPIPS inference. |
net | No | alex | LPIPS backbone name passed to lpips.LPIPS. |
Methods
Public Methods
| Method | Purpose |
|---|---|
calc_lpips(ref_image, edited_image, mask=None) | Compute LPIPS, optionally restricting the effective comparison region. |
__call__(...) | Build the mask and dispatch to calc_lpips. |
Signature
Call Signature
LPIPSPipe.__call__(
ref_image: Image.Image,
edited_image: Image.Image,
coords: List[Tuple[int, int, int, int]] = None,
mask_mode: str = None,
metric: str = "lpips",
**kwargs,
)
Input / Output
Runtime Inputs
| Argument | Required | Meaning |
|---|---|---|
ref_image | Yes | Reference image. |
edited_image | Yes | Edited image. |
coords | No | Pixel-space boxes to measure or exclude. |
mask_mode | No | inner or outer, normally derived from pipeline scope. |
metric | Yes | Currently only lpips. |
Input / Output
Mask Behavior
LPIPSPipe does not crop the image before inference. Instead, when a mask is present it:
- fills the unmeasured region of the edited image with pixels from the reference image
- computes LPIPS on the composited edited image against the original reference image
- scales the resulting score by the measured-area fraction
This area normalization is implemented as:
lpips_score / (computed_area / img_area)
when the mask contains at least one selected pixel.
Input / Output
Return Value
The pipe returns a single float:
- lower is better
0.0means perceptually very similar- larger values indicate stronger perceptual drift
Config
Minimal Config Example
metric_configs:
lpips:
pipe_name: lpips-pipe
default_config: ${pipes_default.lpips-pipe}
init_config:
net: alex
scope: unedit_area
Failure Mode
Failure Modes
This module is relatively stable because it has few branching paths.
The main preconditions are:
coordsmust be valid ifmask_modeis used- input images must already be valid RGB-like arrays when converted through
numpy
Unsupported metrics raise:
ValueError(f"Unsupported metric: {metric}")
Extension
Extension Notes
- Reuse this pipe if you still want a perceptual-distance metric with region support.
- Add a new pipe only if the metric semantics are no longer LPIPS-like.
- If you change area normalization, document the new score interpretation because downstream thresholding may depend on it.