Calculate the PSNR metric. Non-differentiable. Args: rgb: (h, w, 3), in the range of [0, 1] gts: (h, w, 3), in the range of [0, 1] Returns: psnr value
(
rgb: torch.Tensor,
gts: torch.Tensor,
)
| 10 | |
| 11 | |
| 12 | def psnr( |
| 13 | rgb: torch.Tensor, |
| 14 | gts: torch.Tensor, |
| 15 | ) -> float: |
| 16 | """ |
| 17 | Calculate the PSNR metric. Non-differentiable. |
| 18 | |
| 19 | Args: |
| 20 | rgb: (h, w, 3), in the range of [0, 1] |
| 21 | gts: (h, w, 3), in the range of [0, 1] |
| 22 | |
| 23 | Returns: |
| 24 | psnr value |
| 25 | """ |
| 26 | assert (rgb.shape[-1] == 3) |
| 27 | assert (gts.shape[-1] == 3) |
| 28 | |
| 29 | mse = torch.mean((rgb[..., :3] - gts[..., :3]) ** 2).item() |
| 30 | return 10 * np.log10(1.0 / mse) |
| 31 | |
| 32 | |
| 33 | def get_lpips_model(device: torch.device('cpu')) -> torch.nn.Module: |
nothing calls this directly
no outgoing calls
no test coverage detected