MCPcopy Create free account
hub / github.com/Gabesarch/ICAL / gradient2d

Function gradient2d

TEACh/utils/basic.py:414–431  ·  view source on GitHub ↗
(x, absolute=False, square=False)

Source from the content-addressed store, hash-verified

412 return dz, dy, dx
413
414def 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
433def matmul2(mat1, mat2):
434 return torch.matmul(mat1, mat2)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected