mindspore.nn.PSNR
- class mindspore.nn.PSNR(max_val=1.0)[source]
Returns Peak Signal-to-Noise Ratio of two image batches.
It produces a PSNR value for each image in batch. Assume inputs are \(I\) and \(K\), both with shape \(h*w\). \(MAX\) represents the dynamic range of pixel values.
\[\begin{split}MSE&=\frac{1}{hw}\sum\limits_{i=0}^{h-1}\sum\limits_{j=0}^{w-1}[I(i,j)-K(i,j)]^2\\ PSNR&=10*log_{10}(\frac{MAX^2}{MSE})\end{split}\]- Parameters
max_val (Union[int, float]) – The dynamic range of the pixel values (255 for 8-bit grayscale images). The value must be greater than 0. Default: 1.0.
- Inputs:
img1 (Tensor) - The first image batch with format ‘NCHW’. It must be the same shape and dtype as img2.
img2 (Tensor) - The second image batch with format ‘NCHW’. It must be the same shape and dtype as img1.
- Outputs:
Tensor, with dtype mindspore.float32. It is a 1-D tensor with shape N, where N is the batch num of img1.
- Raises
TypeError – If max_val is neither int nor float.
ValueError – If max_val is less than or equal to 0.
ValueError – If length of shape of img1 or img2 is not equal to 4.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> net = nn.PSNR() >>> img1 = Tensor([[[[1, 2, 3, 4], [1, 2, 3, 4]]]]) >>> img2 = Tensor([[[[3, 4, 5, 6], [3, 4, 5, 6]]]]) >>> output = net(img1, img2) >>> print(output) [-6.0206]