(x, absolute=False, square=False)
| 412 | return dz, dy, dx |
| 413 | |
| 414 | def gradient2d(x, absolute=False, square=False): |
| 415 | # x should be B x C x H x W |
| 416 | dh = x[:, :, 1:, :] - x[:, :, :-1, :] |
| 417 | dw = x[:, :, :, 1:] - x[:, :, :, :-1] |
| 418 | |
| 419 | # zeros = tf.zeros_like(x) |
| 420 | zeros = torch.zeros_like(x) |
| 421 | zero_h = zeros[:, :, 0:1, :] |
| 422 | zero_w = zeros[:, :, :, 0:1] |
| 423 | dh = torch.cat([dh, zero_h], axis=2) |
| 424 | dw = torch.cat([dw, zero_w], axis=3) |
| 425 | if absolute: |
| 426 | dh = torch.abs(dh) |
| 427 | dw = torch.abs(dw) |
| 428 | if square: |
| 429 | dh = dh ** 2 |
| 430 | dw = dw ** 2 |
| 431 | return dh, dw |
| 432 | |
| 433 | def matmul2(mat1, mat2): |
| 434 | return torch.matmul(mat1, mat2) |
nothing calls this directly
no outgoing calls
no test coverage detected