# Visualinformationfidelity

> Compute the VisualInformationFidelity metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute VisualInformationFidelity, or asks how to score with VisualInformationFidelity.

- Skill: `qhjqhj00/visualinformationfidelity` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/visualinformationfidelity`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/visualinformationfidelity/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/visualinformationfidelity

---


# visualinformationfidelity

> Metric `VisualInformationFidelity` from `torchmetrics` (torchmetrics.image.VisualInformationFidelity)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with VisualInformationFidelity, or
mentions `torchmetrics.image.VisualInformationFidelity` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.image import VisualInformationFidelity

# VisualInformationFidelity(sigma_n_sq: float = 2.0, reduction: Literal['mean', 'none'] = 'mean', **kwargs: Any) -> None
```

## Library docstring

```
Compute Pixel Based Visual Information Fidelity (VIF_).

As input to ``forward`` and ``update`` the metric accepts the following input

- ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)`` with H,W ≥ 41
- ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)`` with H,W ≥ 41

As output of `forward` and `compute` the metric returns the following output

- ``vif-p`` (:class:`~torch.Tensor`):
    - If ``reduction='mean'`` (default), returns a Tensor mean VIF score.
    - If ``reduction='none'``, returns a tensor of shape ``(N,)`` with VIF values per sample.

Args:
    sigma_n_sq: variance of the visual noise
    reduction: The reduction method for aggregating scores.

        - ``'mean'``: return the average VIF across the batch.
        - ``'none'``: return a VIF score for each sample in the batch.

    kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

Example:
    >>> from torch import randn
    >>> from torchmetrics.image import VisualInformationFidelity
    >>> preds = randn([32, 3, 41, 41], generator=torch.Generator().manual_seed(42))
    >>> target = randn([32, 3, 41, 41], generator=torch.Generator().manual_seed(43))
    >>> vif_mean = VisualInformationFidelity(reduction='mean')
    >>> vif_mean(preds, target)
    tensor(0.0032)
    >>> vif_none = VisualInformationFidelity(reduction='none')
    >>> vif_none(preds, target)
    tensor([0.0040, 0.0049, 0.0017, 0.0039, 0.0041, 0.0043, 0.0030, 0.0028, 0.0012,
            0.0067, 0.0010, 0.0014, 0.0030, 0.0048, 0.0050, 0.0038, 0.0037, 0.0025,
            0.0041, 0.0019, 0.0007, 0.0034, 0.0037, 0.0016, 0.0026, 0.0021, 0.0038,
            0.0033, 0.0031, 0.0020, 0.0036, 0.0057])
```

## Quick recipe

```python
import torchmetrics.image as _m
score = _m.VisualInformationFidelity(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

