Skip to content

Commit 5491b46

Browse files
bottlerfacebook-github-bot
authored andcommitted
Points2vols doc fixes
Summary: Fixes to a couple of comments on points to volumes, make the mask work in round_points_to_volumes, and remove a duplicate rand calculation Reviewed By: nikhilaravi Differential Revision: D29522845 fbshipit-source-id: 86770ba37ef3942b909baf63fd73eed1399635b6
1 parent ae1387b commit 5491b46

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

pytorch3d/ops/points_to_volumes.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,15 @@ def add_points_features_to_volume_densities_features(
157157
of its floating point coordinate. The weights are
158158
determined using a trilinear interpolation scheme.
159159
Trilinear splatting is fully differentiable w.r.t. all input arguments.
160-
mask: A binary mask of shape `(minibatch, N)` determining which 3D points
161-
are going to be converted to the resulting volume.
162-
Set to `None` if all points are valid.
163160
min_weight: A scalar controlling the lowest possible total per-voxel
164161
weight used to normalize the features accumulated in a voxel.
165162
Only active for `mode==trilinear`.
163+
mask: A binary mask of shape `(minibatch, N)` determining which 3D points
164+
are going to be converted to the resulting volume.
165+
Set to `None` if all points are valid.
166+
grid_sizes: `LongTensor` of shape (minibatch, 3) representing the
167+
spatial resolutions of each of the the non-flattened `volumes` tensors,
168+
or None to indicate the whole volume is used for every batch element.
166169
Returns:
167170
volume_features: Output volume of shape `(minibatch, feature_dim, D, H, W)`
168171
volume_densities: Occupancy volume of shape `(minibatch, 1, D, H, W)`
@@ -284,13 +287,15 @@ def splat_points_to_volumes(
284287
volume_features: Batch of input *flattened* feature volumes
285288
of shape `(minibatch, feature_dim, N_voxels)`
286289
volume_densities: Batch of input *flattened* feature volume densities
287-
of shape `(minibatch, 1, N_voxels)`. Each voxel should
290+
of shape `(minibatch, N_voxels, 1)`. Each voxel should
288291
contain a non-negative number corresponding to its
289292
opaqueness (the higher, the less transparent).
290293
grid_sizes: `LongTensor` of shape (minibatch, 3) representing the
291294
spatial resolutions of each of the the non-flattened `volumes` tensors.
292295
Note that the following has to hold:
293296
`torch.prod(grid_sizes, dim=1)==N_voxels`
297+
min_weight: A scalar controlling the lowest possible total per-voxel
298+
weight used to normalize the features accumulated in a voxel.
294299
mask: A binary mask of shape `(minibatch, N)` determining which 3D points
295300
are going to be converted to the resulting volume.
296301
Set to `None` if all points are valid.
@@ -457,9 +462,6 @@ def round_points_to_volumes(
457462
# split into separate coordinate vectors
458463
X, Y, Z = XYZ.split(1, dim=2)
459464

460-
# get random indices for the purpose of adding out-of-bounds values
461-
rand_idx = X.new_zeros(X.shape).random_(0, n_voxels)
462-
463465
# valid - binary indicators of votes that fall into the volume
464466
grid_sizes = grid_sizes.type_as(XYZ)
465467
valid = (
@@ -470,6 +472,8 @@ def round_points_to_volumes(
470472
* (0 <= Z)
471473
* (Z < grid_sizes_xyz[:, None, 2:3])
472474
).long()
475+
if mask is not None:
476+
valid = valid * mask[:, :, None].long()
473477

474478
# get random indices for the purpose of adding out-of-bounds values
475479
rand_idx = valid.new_zeros(X.shape).random_(0, n_voxels)

tests/test_points_to_volumes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def init_cube_point_cloud(
3030
batch_size: int = 10, n_points: int = 100000, rotate_y: bool = True
3131
):
3232
"""
33-
Generate a random point cloud of `n_points` whose points of
34-
which are sampled from faces of a 3D cube.
33+
Generate a random point cloud of `n_points` whose points
34+
are sampled from faces of a 3D cube.
3535
"""
3636

3737
# create the cube mesh batch_size times

0 commit comments

Comments
 (0)