MCPcopy Create free account
hub / github.com/OpenTalker/StyleHEAT / gradient_norm

Function gradient_norm

utils/misc.py:162–174  ·  view source on GitHub ↗

r"""Return the gradient norm of model. Args: model (PyTorch module): Your network.

(model)

Source from the content-addressed store, hash-verified

160
161
162def gradient_norm(model):
163 r"""Return the gradient norm of model.
164
165 Args:
166 model (PyTorch module): Your network.
167
168 """
169 total_norm = 0
170 for p in model.parameters():
171 if p.grad is not None:
172 param_norm = p.grad.norm(2)
173 total_norm += param_norm.item() ** 2
174 return total_norm ** (1. / 2)
175
176
177def random_shift(x, offset=0.05, mode='bilinear', padding_mode='reflection'):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected