PSNRLoss<T>
Models & Types · AiDotNet.LossFunctions
The negative-PSNR objective BasicSR trains restoration networks with: the weighted mean over samples of
10/ln 10 · log(MSE + 1e-8).
Inheritance: LossFunctionBase<T> → PSNRLoss<T>
For Beginners
PSNR (peak signal-to-noise ratio) is the standard quality score for restored images, in decibels. Training directly on (minus) PSNR instead of on the plain squared error makes every image’s improvement count in decibels, so small errors on easy images still matter.
How It Works
BasicSR’s PSNRLoss (basicsr/models/losses/losses.py) takes the MSE of each sample over its remaining axes,
adds 1e-8, and averages loss_weight · 10/ln 10 · log(·) over the batch. Minimizing it maximizes each
sample’s PSNR up to a constant, and because each sample’s gradient is divided by its own MSE, samples that are
already clean are not drowned out by noisy ones. A tensor of rank 1 is one sample.
Example
using AiDotNet.LossFunctions;
using AiDotNet.Tensors.LinearAlgebra;
var loss = new PSNRLoss<float>();
var predicted = new Vector<float>(new[] { 0.9f, 0.2f, 0.7f });
var actual = new Vector<float>(new[] { 1.0f, 0.0f, 1.0f });
float value = loss.CalculateLoss(predicted, actual);
Console.WriteLine($"PSNRLoss = {value:F4}");
Constructors
| Constructor | Summary |
|---|---|
PSNRLoss(double lossWeight) |
Initializes a new instance of the PSNRLoss class. |
Methods
| Method | Summary |
|---|---|
T CalculateLoss(Vector<T> predicted, Vector<T> actual) |
|
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target) |