MCPcopy Create free account
hub / github.com/apple/ml-pointersect / psnr

Function psnr

plib/metrics.py:12–30  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

10
11
12def 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
33def get_lpips_model(device: torch.device('cpu')) -> torch.nn.Module:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected