Skip to content
Discussion options

You must be logged in to vote

As of v1.9.0, you can get per-sample metric values (instead of the default batch-averaged aggregation) using two approaches:

Approach 1 — Functional interface (simplest):

from torchmetrics.functional.image import peak_signal_noise_ratio

psnr_values = []
for img_pred, img_target in zip(preds, targets):
    psnr_values.append(
        peak_signal_noise_ratio(img_pred.unsqueeze(0), img_target.unsqueeze(0), data_range=1.0)
    )
psnr_per_image = torch.stack(psnr_values)

Approach 2 — Custom metric with list state:

import torch
from torchmetrics import Metric
from torchmetrics.functional.image import peak_signal_noise_ratio
from torchmetrics.utilities import dim_zero_cat


class PSNRPerSample(M…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants