MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / psnr

Function psnr

tensorpack/tfutils/symbolic_functions.py:39–70  ·  view source on GitHub ↗

`Peak Signal to Noise Ratio `_. .. math:: PSNR = 20 \cdot \log_{10}(MAX_p) - 10 \cdot \log_{10}(MSE) Args: prediction: a :class:`tf.Tensor` representing the prediction signal. ground_truth: another :class:`t

(prediction, ground_truth, maxp=None, name='psnr')

Source from the content-addressed store, hash-verified

37
38# don't hurt to leave it here
39def psnr(prediction, ground_truth, maxp=None, name='psnr'):
40 """`Peak Signal to Noise Ratio <https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio>`_.
41
42 .. math::
43
44 PSNR = 20 \cdot \log_{10}(MAX_p) - 10 \cdot \log_{10}(MSE)
45
46 Args:
47 prediction: a :class:`tf.Tensor` representing the prediction signal.
48 ground_truth: another :class:`tf.Tensor` with the same shape.
49 maxp: maximum possible pixel value of the image (255 in in 8bit images)
50
51 Returns:
52 A scalar tensor representing the PSNR
53 """
54
55 maxp = float(maxp)
56
57 def log10(x):
58 with tf.name_scope("log10"):
59 numerator = tf.log(x)
60 denominator = tf.log(tf.constant(10, dtype=numerator.dtype))
61 return numerator / denominator
62
63 mse = tf.reduce_mean(tf.square(prediction - ground_truth))
64 if maxp is None:
65 psnr = tf.multiply(log10(mse), -10., name=name)
66 else:
67 psnr = tf.multiply(log10(mse), -10.)
68 psnr = tf.add(tf.multiply(20., log10(maxp)), psnr, name=name)
69
70 return psnr

Callers

nothing calls this directly

Calls 2

log10Function · 0.85
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…