mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-18 22:04:02 +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
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Test losses
|
||||
"""
|
||||
|
||||
import torch
|
||||
|
||||
from nerfstudio.model_components.losses import tv_loss
|
||||
|
||||
|
||||
def test_tv_loss():
|
||||
"""Test total variation loss"""
|
||||
|
||||
grids = torch.ones([3, 64, 128, 128])
|
||||
assert tv_loss(grids).item() == 0
|
||||
|
||||
grids = torch.zeros([1, 10, 100, 100])
|
||||
for i in range(100):
|
||||
for j in range(100):
|
||||
grid_location = (i + j) % 2
|
||||
for k in range(10):
|
||||
grids[0, k, i, j] = grid_location
|
||||
|
||||
# TV_row = 1, TV_col = 1. Totol tv should be 2 * (TV_row + TV_col)
|
||||
assert tv_loss(grids).item() == 4.0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_tv_loss()
|
||||
Reference in new issue
Block a user