Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:correction of PairPixelSampler in case of using masks with depth-nerfacto #2477

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions nerfstudio/data/pixel_samplers.py
Expand Up @@ -399,10 +399,11 @@ def sample_method( # pylint: disable=no-self-use
mask: Optional[Tensor] = None,
device: Union[torch.device, str] = "cpu",
) -> Int[Tensor, "batch_size 3"]:
rays_to_sample = self.rays_to_sample
if isinstance(mask, Tensor):
m = erode_mask(mask.permute(0, 3, 1, 2).float(), pixel_radius=self.radius)
nonzero_indices = torch.nonzero(m[:, 0], as_tuple=False).to(device)
chosen_indices = random.sample(range(len(nonzero_indices)), k=self.rays_to_sample)
chosen_indices = random.sample(range(len(nonzero_indices)), k=rays_to_sample)
indices = nonzero_indices[chosen_indices]
else:
rays_to_sample = self.rays_to_sample
Expand All @@ -418,12 +419,12 @@ def sample_method( # pylint: disable=no-self-use
ws = torch.randint(self.radius, image_width - self.radius, s, dtype=torch.long, device=device)
indices = torch.concat((ns, hs, ws), dim=1)

pair_indices = torch.hstack(
(
torch.zeros(rays_to_sample, 1, device=device, dtype=torch.long),
torch.randint(-self.radius, self.radius, (rays_to_sample, 2), device=device, dtype=torch.long),
)
pair_indices = torch.hstack(
(
torch.zeros(rays_to_sample, 1, device=device, dtype=torch.long),
torch.randint(-self.radius, self.radius, (rays_to_sample, 2), device=device, dtype=torch.long),
)
pair_indices += indices
indices = torch.hstack((indices, pair_indices)).view(rays_to_sample * 2, 3)
)
pair_indices += indices
indices = torch.hstack((indices, pair_indices)).view(rays_to_sample * 2, 3)
return indices