mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
fix:correction of PairPixelSampler in case of using masks with depth-nerfacto (#2477)
fix:correction of PairPixelSampler in case of using masks
This commit is contained in:
1 parent
c93b374d08
commit
7856aa0060
1 file changed
+9
-8
@@ -399,10 +399,11 @@ class PairPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods
|
|||||||
mask: Optional[Tensor] = None,
|
mask: Optional[Tensor] = None,
|
||||||
device: Union[torch.device, str] = "cpu",
|
device: Union[torch.device, str] = "cpu",
|
||||||
) -> Int[Tensor, "batch_size 3"]:
|
) -> Int[Tensor, "batch_size 3"]:
|
||||||
|
rays_to_sample = self.rays_to_sample
|
||||||
if isinstance(mask, Tensor):
|
if isinstance(mask, Tensor):
|
||||||
m = erode_mask(mask.permute(0, 3, 1, 2).float(), pixel_radius=self.radius)
|
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)
|
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]
|
indices = nonzero_indices[chosen_indices]
|
||||||
else:
|
else:
|
||||||
rays_to_sample = self.rays_to_sample
|
rays_to_sample = self.rays_to_sample
|
||||||
@@ -418,12 +419,12 @@ class PairPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods
|
|||||||
ws = torch.randint(self.radius, image_width - self.radius, s, dtype=torch.long, device=device)
|
ws = torch.randint(self.radius, image_width - self.radius, s, dtype=torch.long, device=device)
|
||||||
indices = torch.concat((ns, hs, ws), dim=1)
|
indices = torch.concat((ns, hs, ws), dim=1)
|
||||||
|
|
||||||
pair_indices = torch.hstack(
|
pair_indices = torch.hstack(
|
||||||
(
|
(
|
||||||
torch.zeros(rays_to_sample, 1, device=device, dtype=torch.long),
|
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),
|
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
|
return indices
|
||||||
Reference in new issue
Block a user