r"""Return the gradient norm of model. Args: model (PyTorch module): Your network.
(model)
| 160 | |
| 161 | |
| 162 | def 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 | |
| 177 | def random_shift(x, offset=0.05, mode='bilinear', padding_mode='reflection'): |
nothing calls this directly
no outgoing calls
no test coverage detected