mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-19 14:23:57 +08:00
implementing l1 and tv reg in the original tensorf paper (#1855)
* implementing l1 and tv reg in the original tensorf paper * added documentation for tv loss * added test for tv loss * fix formating * fix formatting --------- Co-authored-by: Yan Xiao <yax010@ucsd.edu>
This commit is contained in:
1 parent
f92275603a
commit
38cbb0f358
4 files changed
+77
-3
No files matched your search
@@ -485,3 +485,20 @@ class ScaleAndShiftInvariantLoss(nn.Module):
|
||||
return self.__prediction_ssi
|
||||
|
||||
prediction_ssi = property(__get_prediction_ssi)
|
||||
|
||||
|
||||
def tv_loss(grids: TensorType["grids", "feature_dim", "row", "column"]) -> TensorType[()]:
|
||||
"""
|
||||
https://github.com/apchenstu/TensoRF/blob/4ec894dc1341a2201fe13ae428631b58458f105d/utils.py#L139
|
||||
|
||||
Args:
|
||||
grids: stacks of explicit feature grids (stacked at dim 0)
|
||||
Returns:
|
||||
average total variation loss for neighbor rows and columns.
|
||||
"""
|
||||
number_of_grids = grids.shape[0]
|
||||
h_tv_count = grids[:, :, 1:, :].shape[1] * grids[:, :, 1:, :].shape[2] * grids[:, :, 1:, :].shape[3]
|
||||
w_tv_count = grids[:, :, :, 1:].shape[1] * grids[:, :, :, 1:].shape[2] * grids[:, :, :, 1:].shape[3]
|
||||
h_tv = torch.pow((grids[:, :, 1:, :] - grids[:, :, :-1, :]), 2).sum()
|
||||
w_tv = torch.pow((grids[:, :, :, 1:] - grids[:, :, :, :-1]), 2).sum()
|
||||
return 2 * (h_tv / h_tv_count + w_tv / w_tv_count) / number_of_grids
|
||||
Reference in new issue
Block a user