(input)
| 32 | |
| 33 | # Computes gradient for a tensor |
| 34 | def tensor_gradient(input): |
| 35 | input0 = input[..., :-1, :-1] |
| 36 | didy = input[..., 1:, :-1] - input0 |
| 37 | didx = input[..., :-1, 1:] - input0 |
| 38 | return torch.cat((didy, didx), -3) |
| 39 | |
| 40 | # Compares two image tensors using the specified error metric |
| 41 | def compare_images(a, b, metric='psnr'): |