---
title: registry
---

<div class="python-reference">
<a id="fastvideo.eval.registry-classes"></a>
<a id="fastvideo.eval.registry-functions"></a>
<a id="fastvideo.eval.registry"></a>

<h2 id="fastvideo.eval.registry.BaseMetric"><code>fastvideo.eval.registry.BaseMetric</code></h2>
<pre class="doc-signature"><code>BaseMetric()</code></pre>
<p>Abstract base class for all eval metrics.</p>
<p>Two execution shapes:</p>
<ul>
<li>
<p><strong>Per-sample</strong> (<code>is_set_metric=False</code>, default) — implement
  :meth:<code>compute</code>. The Evaluator calls it once per input sample and
  returns one :class:<code>MetricResult</code> per sample.</p>
</li>
<li>
<p><strong>Set-vs-set</strong> (<code>is_set_metric=True</code>) — implement
  :meth:<code>accumulate</code> (called once per sample to buffer features)
  and :meth:<code>finalize</code> (called once after all samples to compute
  the corpus-level result). Use :meth:<code>reset</code> to clear buffers and
  :meth:<code>merge_from</code> to fold multi-GPU per-worker state together.</p>
</li>
</ul>
<p>Optionally override :meth:<code>setup</code> to eagerly load models. Metrics
that chunk along the time dim for memory hardcode their own chunk
size in <code>__init__</code> (see <code>optical_flow</code> for the canonical
example). Eval always processes one video per
:meth:<code>Evaluator.evaluate</code> call; <code>compute</code> / <code>accumulate</code>
receive a single sample, not a batch.</p>

<h3 id="fastvideo.eval.registry.BaseMetric.to"><code>fastvideo.eval.registry.BaseMetric.to</code></h3>
<pre class="doc-signature"><code>to(device: str | torch.device) -&gt; BaseMetric</code></pre>
<p>Move metric (and its internal models) to <em>device</em>.</p>
<h3 id="fastvideo.eval.registry.BaseMetric.setup"><code>fastvideo.eval.registry.BaseMetric.setup</code></h3>
<pre class="doc-signature"><code>setup() -&gt; None</code></pre>
<p>Eagerly load models. Called once by :class:<code>EvalWorker</code>.</p>
<p>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.</p>
<h3 id="fastvideo.eval.registry.BaseMetric.compute"><code>fastvideo.eval.registry.BaseMetric.compute</code></h3>
<pre class="doc-signature"><code>compute(sample: dict) -&gt; MetricResult</code></pre>
<p>Per-sample metrics: compute the score for one sample.</p>
<p><code>sample["video"]</code> is <code>(T, C, H, W)</code> float in <code>[0, 1]</code>.
<code>sample["reference"]</code> (if used) has the same shape. Return
<code>self._skip(sample, reason)</code> for missing inputs.</p>
<h3 id="fastvideo.eval.registry.BaseMetric.reset"><code>fastvideo.eval.registry.BaseMetric.reset</code></h3>
<pre class="doc-signature"><code>reset() -&gt; None</code></pre>
<p>Clear accumulator state at the start of each evaluate() call.</p>
<h3 id="fastvideo.eval.registry.BaseMetric.accumulate"><code>fastvideo.eval.registry.BaseMetric.accumulate</code></h3>
<pre class="doc-signature"><code>accumulate(sample: dict) -&gt; None</code></pre>
<p>Buffer per-sample features for a corpus-level metric.</p>
<h3 id="fastvideo.eval.registry.BaseMetric.finalize"><code>fastvideo.eval.registry.BaseMetric.finalize</code></h3>
<pre class="doc-signature"><code>finalize() -&gt; MetricResult</code></pre>
<p>Compute the corpus-level result from buffered state.</p>
<h3 id="fastvideo.eval.registry.BaseMetric.merge_from"><code>fastvideo.eval.registry.BaseMetric.merge_from</code></h3>
<pre class="doc-signature"><code>merge_from(other: BaseMetric) -&gt; None</code></pre>
<p>Multi-GPU: fold another worker's accumulator state into this one.</p>
<h2 id="fastvideo.eval.registry.register"><code>fastvideo.eval.registry.register</code></h2>
<pre class="doc-signature"><code>register(name: str)</code></pre>
<p>Decorator to register a metric class.</p>
<p>Usage::</p>
<pre><code>@register("ssim")
class SSIMMetric(BaseMetric):
    ...
</code></pre>
<details><summary>Source</summary><pre><code>def register(name: str):
    &quot;&quot;&quot;Decorator to register a metric class.

    Usage::

        @register(&quot;ssim&quot;)
        class SSIMMetric(BaseMetric):
            ...
    &quot;&quot;&quot;

    def wrapper(cls):
        _REGISTRY&#91;name&#93; = cls
        return cls

    return wrapper</code></pre></details>
<h2 id="fastvideo.eval.registry.get_metric"><code>fastvideo.eval.registry.get_metric</code></h2>
<pre class="doc-signature"><code>get_metric(name: str, **kwargs: Any) -&gt; BaseMetric</code></pre>
<p>Instantiate a registered metric by name.</p>
<p>Checks that optional dependencies are installed before instantiation
and gives a clear install hint pointing at the right extra group.</p>
<details><summary>Source</summary><pre><code>def get_metric(name: str, **kwargs: Any) -&gt; BaseMetric:
    &quot;&quot;&quot;Instantiate a registered metric by name.

    Checks that optional dependencies are installed before instantiation
    and gives a clear install hint pointing at the right extra group.
    &quot;&quot;&quot;
    cls = _REGISTRY.get(name)
    if cls is None:
        available = &quot;, &quot;.join(sorted(_REGISTRY.keys()))
        raise KeyError(f&quot;Unknown metric &#x27;&#123;name&#125;&#x27;. Available: &#123;available&#125;&quot;)

    for dep in getattr(cls, &quot;dependencies&quot;, &#91;&#93;):
        if not importlib.util.find_spec(dep):
            raise ImportError(f&quot;&#123;cls.__name__&#125; requires &#x27;&#123;dep&#125;&#x27;. &quot;
                              f&quot;Install with: &#123;_install_hint(name, dep)&#125;&quot;)

    return cls(**kwargs)</code></pre></details>
<h2 id="fastvideo.eval.registry.missing_dependencies"><code>fastvideo.eval.registry.missing_dependencies</code></h2>
<pre class="doc-signature"><code>missing_dependencies(metric_name: str) -&gt; list&#91;str&#93;</code></pre>
<p>Importable module names declared by <em>metric_name</em> that are not
actually importable in this environment. Returns <code>[]</code> if all deps
are satisfied or the metric is unknown.</p>
<p>Used by group-style resolution to decide which metrics to silently
skip (vs. naming a metric explicitly, where the missing dep should
surface as :class:<code>ImportError</code>).</p>
<details><summary>Source</summary><pre><code>def missing_dependencies(metric_name: str) -&gt; list&#91;str&#93;:
    &quot;&quot;&quot;Importable module names declared by *metric_name* that are not
    actually importable in this environment. Returns ``&#91;&#93;`` if all deps
    are satisfied or the metric is unknown.

    Used by group-style resolution to decide which metrics to silently
    skip (vs. naming a metric explicitly, where the missing dep should
    surface as :class:`ImportError`).
    &quot;&quot;&quot;
    cls = _REGISTRY.get(metric_name)
    if cls is None:
        return &#91;&#93;
    return &#91;d for d in getattr(cls, &quot;dependencies&quot;, &#91;&#93;) if not importlib.util.find_spec(d)&#93;</code></pre></details>
<h2 id="fastvideo.eval.registry.list_metrics"><code>fastvideo.eval.registry.list_metrics</code></h2>
<pre class="doc-signature"><code>list_metrics() -&gt; list&#91;str&#93;</code></pre>
<p>Return sorted list of all registered metric names.</p>
<details><summary>Source</summary><pre><code>def list_metrics() -&gt; list&#91;str&#93;:
    &quot;&quot;&quot;Return sorted list of all registered metric names.&quot;&quot;&quot;
    return sorted(_REGISTRY.keys())</code></pre></details>
<h2 id="fastvideo.eval.registry.resolve_group"><code>fastvideo.eval.registry.resolve_group</code></h2>
<pre class="doc-signature"><code>resolve_group(name: str) -&gt; list&#91;str&#93; | None</code></pre>
<p>If <em>name</em> is a group prefix (e.g. <code>"vbench"</code>), return all matching
metric names.  Returns <code>None</code> if <em>name</em> is not a group.</p>
<details><summary>Source</summary><pre><code>def resolve_group(name: str) -&gt; list&#91;str&#93; | None:
    &quot;&quot;&quot;If *name* is a group prefix (e.g. ``&quot;vbench&quot;``), return all matching
    metric names.  Returns ``None`` if *name* is not a group.&quot;&quot;&quot;
    prefix = name + &quot;.&quot;
    matches = sorted(k for k in _REGISTRY if k.startswith(prefix))
    return matches if matches else None</code></pre></details>
</div>
