change normals grad calculation (#1108)

* change normals grad calculation

* changing normal calc
This commit is contained in:
Terrance Wang authored and GitHub committed 2022-12-13 12:39:41 -08:00
1 parent 1a70665e76
commit 008cc8f144
1 file changed
+9 -4
+9 -4
View File
@@ -74,10 +74,15 @@ class Field(nn.Module):
self._sample_locations.shape[:-1] == self._density_before_activation.shape[:-1] self._sample_locations.shape[:-1] == self._density_before_activation.shape[:-1]
), "Sample locations and density must have the same shape besides the last dimension." ), "Sample locations and density must have the same shape besides the last dimension."
self._density_before_activation.backward( normals = torch.autograd.grad(
gradient=torch.ones_like(self._density_before_activation), inputs=self._sample_locations, retain_graph=True self._density_before_activation,
) self._sample_locations,
normals = -torch.nn.functional.normalize(self._sample_locations.grad, dim=-1) grad_outputs=torch.ones_like(self._density_before_activation),
retain_graph=True,
)[0]
normals = -torch.nn.functional.normalize(normals, dim=-1)
return normals return normals
@abstractmethod @abstractmethod