(
ground_truth: Float[Tensor, "batch channel height width"],
predicted: Float[Tensor, "batch channel height width"],
)
| 10 | |
| 11 | @torch.no_grad() |
| 12 | def compute_psnr( |
| 13 | ground_truth: Float[Tensor, "batch channel height width"], |
| 14 | predicted: Float[Tensor, "batch channel height width"], |
| 15 | ) -> Float[Tensor, " batch"]: |
| 16 | ground_truth = ground_truth.clip(min=0, max=1) |
| 17 | predicted = predicted.clip(min=0, max=1) |
| 18 | mse = reduce((ground_truth - predicted) ** 2, "b c h w -> b", "mean") |
| 19 | return -10 * mse.log10() |
| 20 | |
| 21 | |
| 22 | @cache |
no outgoing calls
no test coverage detected