(self, x)
| 94 | return self.forward(x) |
| 95 | |
| 96 | def gradient(self, x): |
| 97 | x.requires_grad_(True) |
| 98 | y = self.sdf(x) |
| 99 | d_output = torch.ones_like(y, requires_grad=False, device=y.device) |
| 100 | gradients = torch.autograd.grad( |
| 101 | outputs=y, |
| 102 | inputs=x, |
| 103 | grad_outputs=d_output, |
| 104 | create_graph=True, |
| 105 | retain_graph=True, |
| 106 | only_inputs=True)[0] |
| 107 | return gradients.unsqueeze(1) |
| 108 | |
| 109 | |
| 110 | # This implementation is borrowed from IDR: https://github.com/lioryariv/idr |