Skip to content
FastVideo
Esc
↑↓navigate↵open⌘Jpreview
On this page

metric

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric

BaseMetric()

Abstract base class for all eval metrics.

Two execution shapes:

  • Per-sample (is_set_metric=False, default) — implement :meth:compute. The Evaluator calls it once per input sample and returns one :class:MetricResult per sample.

  • Set-vs-set (is_set_metric=True) — implement :meth:accumulate (called once per sample to buffer features) and :meth:finalize (called once after all samples to compute the corpus-level result). Use :meth:reset to clear buffers and :meth:merge_from to fold multi-GPU per-worker state together.

Optionally override :meth:setup to eagerly load models. Metrics that chunk along the time dim for memory hardcode their own chunk size in __init__ (see optical_flow for the canonical example). Eval always processes one video per :meth:Evaluator.evaluate call; compute / accumulate receive a single sample, not a batch.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.to

to(device: str | torch.device) -> BaseMetric

Move metric (and its internal models) to device.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.setup

setup() -> None

Eagerly load models. Called once by :class:EvalWorker.

Default is a no-op; metrics with no eager state (pixel math, closed-form ops) inherit this. Override only if your metric needs to load weights.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.compute

compute(sample: dict) -> MetricResult

Per-sample metrics: compute the score for one sample.

sample["video"] is (T, C, H, W) float in [0, 1]. sample["reference"] (if used) has the same shape. Return self._skip(sample, reason) for missing inputs.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.reset

reset() -> None

Clear accumulator state at the start of each evaluate() call.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.accumulate

accumulate(sample: dict) -> None

Buffer per-sample features for a corpus-level metric.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.finalize

finalize() -> MetricResult

Compute the corpus-level result from buffered state.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.BaseMetric.merge_from

merge_from(other: BaseMetric) -> None

Multi-GPU: fold another worker's accumulator state into this one.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.register

register(name: str)

Decorator to register a metric class.

Usage::

@register("ssim")
class SSIMMetric(BaseMetric):
    ...

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.MetricResult

MetricResult(name: str, score: float | None, details: dict[str, Any] = dict())

Standard result container returned by all metrics.

score is None when the metric was skipped (e.g. missing required input). Check details["skipped"] for the reason.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.compute_weighted_spatial_iou

compute_weighted_spatial_iou(mask1_frames: np.ndarray, mask2_frames: np.ndarray) -> float

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.prepare_pair

prepare_pair(sample: dict[str, Any], *, prep_kwargs: dict[str, Any] | None = None) -> PreparedPhysicsIQPair

Resolve a sample into a prepared (gen, ref) pair.

Caches the result on sample['_physics_iq_pair'] so other physics_iq sub-metrics on the same sample reuse it instead of re-decoding.

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.WeightedSpatialIoUMetric

WeightedSpatialIoUMetric(**kwargs: Any)
Source
@register("physics_iq.weighted_spatial_iou")
class WeightedSpatialIoUMetric(BaseMetric):
    name = "physics_iq.weighted_spatial_iou"
    requires_reference = True
    higher_is_better = True
def __init__(self, **kwargs: Any) -> None:
    super().__init__()
    self._kwargs = kwargs

def compute(self, sample: dict) -> MetricResult:
    prepared = prepare_pair(sample, prep_kwargs=self._kwargs)
    score = compute_weighted_spatial_iou(prepared.reference_masks, prepared.generated_masks)
    return MetricResult(name=self.name, score=score, details=&#123;&#125;)</code></pre></details>

fastvideo.eval.metrics.physics_iq.weighted_spatial_iou.metric.WeightedSpatialIoUMetric.compute

compute(sample: dict) -> MetricResult
Source
def compute(self, sample: dict) -> MetricResult:
    prepared = prepare_pair(sample, prep_kwargs=self._kwargs)
    score = compute_weighted_spatial_iou(prepared.reference_masks, prepared.generated_masks)
    return MetricResult(name=self.name, score=score, details={})

Was this page helpful?