Skip to content

Commit 611aba9

Browse files
bottlerfacebook-github-bot
authored andcommitted
replicate_last_interval in raymarcher
Summary: Add option to flat pad the last delta. Might to help when training on rgb only. Reviewed By: shapovalov Differential Revision: D40587475 fbshipit-source-id: c763fa38948600ea532c730538dc4ff29d2c3e0a
1 parent ff933ab commit 611aba9

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

projects/implicitron_trainer/tests/experiment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,15 @@ model_factory_ImplicitronModelFactory_args:
235235
surface_thickness: 1
236236
bg_color:
237237
- 0.0
238+
replicate_last_interval: False
238239
background_opacity: 0.0
239240
density_relu: true
240241
blend_output: false
241242
raymarcher_EmissionAbsorptionRaymarcher_args:
242243
surface_thickness: 1
243244
bg_color:
244245
- 0.0
246+
replicate_last_interval: False
245247
background_opacity: 10000000000.0
246248
density_relu: true
247249
blend_output: false

pytorch3d/implicitron/models/renderer/raymarcher.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ class AccumulativeRaymarcherBase(RaymarcherBase, torch.nn.Module):
5555
surface_thickness: The thickness of the raymarched surface.
5656
bg_color: The background color. A tuple of either 1 element or of D elements,
5757
where D matches the feature dimensionality; it is broadcast when necessary.
58-
background_opacity: The raw opacity value (i.e. before exponentiation)
59-
of the background.
58+
replicate_last_interval: If True, the ray length assigned to the last interval
59+
for the opacity delta calculation is copied from the penultimate interval.
60+
background_opacity: The length over which the last raw opacity value
61+
(i.e. before exponentiation) is considered to apply, for the delta
62+
calculation. Ignored if replicate_last_interval=True.
6063
density_relu: If `True`, passes the input density through ReLU before
6164
raymarching.
6265
blend_output: If `True`, alpha-blends the output renders with the
@@ -76,6 +79,7 @@ class AccumulativeRaymarcherBase(RaymarcherBase, torch.nn.Module):
7679

7780
surface_thickness: int = 1
7881
bg_color: Tuple[float, ...] = (0.0,)
82+
replicate_last_interval: bool = False
7983
background_opacity: float = 0.0
8084
density_relu: bool = True
8185
blend_output: bool = False
@@ -151,13 +155,14 @@ def forward(
151155
density_1d=True,
152156
)
153157

154-
deltas = torch.cat(
155-
(
156-
ray_lengths[..., 1:] - ray_lengths[..., :-1],
157-
self.background_opacity * torch.ones_like(ray_lengths[..., :1]),
158-
),
159-
dim=-1,
160-
)
158+
ray_lengths_diffs = ray_lengths[..., 1:] - ray_lengths[..., :-1]
159+
if self.replicate_last_interval:
160+
last_interval = ray_lengths_diffs[..., -1:]
161+
else:
162+
last_interval = torch.full_like(
163+
ray_lengths[..., :1], self.background_opacity
164+
)
165+
deltas = torch.cat((ray_lengths_diffs, last_interval), dim=-1)
161166

162167
rays_densities = rays_densities[..., 0]
163168

0 commit comments

Comments
 (0)