MCPcopy Create free account
hub / github.com/DragonisCV/RAM / attr_grad

Function attr_grad

scripts/analysis_utils.py:55–62  ·  view source on GitHub ↗

Calculate attribute gradient.

(tensor, reduce='sum')

Source from the content-addressed store, hash-verified

53 raise NotImplementedError()
54
55def attr_grad(tensor, reduce='sum'):
56 """Calculate attribute gradient."""
57 h_x = tensor.size()[2]
58 w_x = tensor.size()[3]
59 h_grad = torch.pow(tensor[:, :, :h_x - 1, :] - tensor[:, :, 1:, :], 2)
60 w_grad = torch.pow(tensor[:, :, :, :w_x - 1] - tensor[:, :, :, 1:], 2)
61 grad = torch.pow(h_grad[:, :, :, :-1] + w_grad[:, :, :-1, :], 1 / 2)
62 return reduce_func(reduce)(grad)
63
64def attr_gabor_generator(gabor_filter):
65 """Generate attribute gabor function."""

Callers 3

_integrated_gradientsMethod · 0.90

Calls 1

reduce_funcFunction · 0.85

Tested by

no test coverage detected