Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nr3d_lib/graphics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def PSNR(x: torch.Tensor, y: torch.Tensor, mask: torch.BoolTensor=None, only_in_
if (mask is not None):
mask = mask.view(*x.shape[:-1])
if only_in_mask:
mse = ((x - y)**2)[mask].sum() / mask.sum().clip(1e-5)
# NOTE: The mask should be expanded to match the shape of x (or y); otherwise, the PSNR may be lower than expected.
mask_expanded = mask.view(*x.shape[:-1]).unsqueeze(-1).expand_as(x)
mse = ((x - y)**2)[mask_expanded].sum() / mask_expanded.sum().clip(1e-5)
else:
# NOTE: x should not be masked;
# and the convergence of mask will also affect performance here (which is expected)
Expand Down