Skip to main content

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

FieldValue
Registry keylpips-pipe
ClassLPIPSPipe
Main mixinsLPIPSMixin, MaskProcessor
Return typefloat
Constructor

Constructor

LPIPSPipe(**kwargs)

Supported init kwargs

KeyRequiredDefaultMeaning
deviceNoautoTorch device for LPIPS inference.
netNoalexLPIPS backbone name passed to lpips.LPIPS.
Methods

Public Methods

MethodPurpose
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

ArgumentRequiredMeaning
ref_imageYesReference image.
edited_imageYesEdited image.
coordsNoPixel-space boxes to measure or exclude.
mask_modeNoinner or outer, normally derived from pipeline scope.
metricYesCurrently only lpips.
Input / Output

Mask Behavior

LPIPSPipe does not crop the image before inference. Instead, when a mask is present it:

  1. fills the unmeasured region of the edited image with pixels from the reference image
  2. computes LPIPS on the composited edited image against the original reference image
  3. 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.0 means 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:

  • coords must be valid if mask_mode is 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.