Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import math
2from fastai.metrics import mse
4def psnr(input, target, max=2.0):
5 """
6 A metric to calculate the peak signal-to-noise ratio.
8 It is given in eq. 3 of
9 PSNR = 10 \log_{10}(\frac{I^2}{L_{2_{Loss}}})
10 where I = 2 because the HR and SR pixel values are between [-1,1].
11 """
12 L2 = mse(input, target)
13 return 10 * math.log10(max**2/L2)