Skip to content

Commit 3d7dea5

Browse files
gkioxarifacebook-github-bot
authored andcommitted
remove unused params + cubify note
Summary: This diff * removes the unused compositing params * adds a note describing cubify Reviewed By: nikhilaravi Differential Revision: D22426191 fbshipit-source-id: e8aa32040bb594e1dfd7d6d98e29264feefcec7c
1 parent 38eadb7 commit 3d7dea5

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

docs/notes/cubify.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Cubify
2+
3+
The [cubify operator](https://github.com/facebookresearch/pytorch3d/blob/master/pytorch3d/ops/cubify.py) converts an 3D occupancy grid of shape `BxDxHxW`, where `B` is the batch size, into a mesh instantiated as a [Meshes](https://github.com/facebookresearch/pytorch3d/blob/master/pytorch3d/structures/meshes.py) data structure of `B` elements. The operator replaces every occupied voxel (if its occupancy probability is greater than a user defined threshold) with a cuboid of 12 faces and 8 vertices. Shared vertices are merged, and internal faces are removed resulting in a **watertight** mesh.
4+
5+
The operator provides three alignment modes {*topleft*, *corner*, *center*} which define the span of the mesh vertices with respect to the voxel grid. The alignment modes are described in the figure below for a 2D grid.
6+
7+
![input](https://user-images.githubusercontent.com/4369065/81032959-af697380-8e46-11ea-91a8-fae89597f988.png)

pytorch3d/renderer/compositing.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
# This can be an image (C=3) or a set of features.
1515

1616

17-
# Data class to store blending params with defaults
18-
class CompositeParams(NamedTuple):
19-
radius: float = 4.0 / 256.0
20-
21-
2217
class _CompositeAlphaPoints(torch.autograd.Function):
2318
"""
2419
Composite features within a z-buffer using alpha compositing. Given a z-buffer
@@ -67,7 +62,7 @@ def backward(ctx, grad_output):
6762
return grad_features, grad_alphas, grad_points_idx, None
6863

6964

70-
def alpha_composite(pointsidx, alphas, pt_clds, blend_params=None) -> torch.Tensor:
65+
def alpha_composite(pointsidx, alphas, pt_clds) -> torch.Tensor:
7166
"""
7267
Composite features within a z-buffer using alpha compositing. Given a z-buffer
7368
with corresponding features and weights, these values are accumulated according
@@ -147,7 +142,7 @@ def backward(ctx, grad_output):
147142
return grad_features, grad_alphas, grad_points_idx, None
148143

149144

150-
def norm_weighted_sum(pointsidx, alphas, pt_clds, blend_params=None) -> torch.Tensor:
145+
def norm_weighted_sum(pointsidx, alphas, pt_clds) -> torch.Tensor:
151146
"""
152147
Composite features within a z-buffer using normalized weighted sum. Given a z-buffer
153148
with corresponding features and weights, these values are accumulated
@@ -226,7 +221,7 @@ def backward(ctx, grad_output):
226221
return grad_features, grad_alphas, grad_points_idx, None
227222

228223

229-
def weighted_sum(pointsidx, alphas, pt_clds, blend_params=None) -> torch.Tensor:
224+
def weighted_sum(pointsidx, alphas, pt_clds) -> torch.Tensor:
230225
"""
231226
Composite features within a z-buffer using normalized weighted sum.
232227

pytorch3d/renderer/points/compositor.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import torch
44
import torch.nn as nn
55

6-
from ..compositing import CompositeParams, alpha_composite, norm_weighted_sum
6+
from ..compositing import alpha_composite, norm_weighted_sum
77

88

99
# A compositor should take as input 3D points and some corresponding information.
@@ -16,15 +16,11 @@ class AlphaCompositor(nn.Module):
1616
Accumulate points using alpha compositing.
1717
"""
1818

19-
def __init__(self, composite_params=None):
19+
def __init__(self):
2020
super().__init__()
2121

22-
self.composite_params = (
23-
composite_params if composite_params is not None else CompositeParams()
24-
)
25-
2622
def forward(self, fragments, alphas, ptclds, **kwargs) -> torch.Tensor:
27-
images = alpha_composite(fragments, alphas, ptclds, self.composite_params)
23+
images = alpha_composite(fragments, alphas, ptclds)
2824
return images
2925

3026

@@ -33,12 +29,9 @@ class NormWeightedCompositor(nn.Module):
3329
Accumulate points using a normalized weighted sum.
3430
"""
3531

36-
def __init__(self, composite_params=None):
32+
def __init__(self):
3733
super().__init__()
38-
self.composite_params = (
39-
composite_params if composite_params is not None else CompositeParams()
40-
)
4134

4235
def forward(self, fragments, alphas, ptclds, **kwargs) -> torch.Tensor:
43-
images = norm_weighted_sum(fragments, alphas, ptclds, self.composite_params)
36+
images = norm_weighted_sum(fragments, alphas, ptclds)
4437
return images

0 commit comments

Comments
 (0)