Monodepth Regularization (#2284)

* monodepth implemented

* device

* pair pixel sampler

* docstring

* removing unused imports

* fix bugs

* cache in cache dir, no longer edit json file

* moving to depth nerfacto

* fixed bug using median depth by accident

* removing depthdataset from nerfacto

* added pixelsamplerconfig

* added equirectangular warning back

* bug fix

* delete sample_config.py + small fixes

* rename to pixel_sampler

* cleaning

* test

* passing num_rays_per_batch properly

* fixed transforms typo

* renaming in nerfacto

* remove depth files from test data

* removed defaulting to base pixel sampler with mask

* adding patch_size back

---------

Co-authored-by: AdamRashid96 <abrashid@berkeley.edu>
Co-authored-by: Matthew Tancik <tancik@berkeley.edu>
This commit is contained in:
authored and GitHub committed 2023-08-01 18:52:47 -07:00
1 parent 72da747fc2
commit 71c6b9cf3d
8 files changed
+293 -89

No files matched your search

+14
View File
@@ -35,6 +35,7 @@ EPS = 1.0e-7
# Sigma scale factor from Urban Radiance Fields (Rematas et al., 2022)
URF_SIGMA_SCALE_FACTOR = 3.0
DEPTH_METRIC = 1
class DepthLossType(Enum):
@@ -561,3 +562,16 @@ def scale_gradients_by_distance_squared(
for key, value in field_outputs.items():
out[key], _ = cast(Tuple[Tensor, Tensor], _GradientScaler.apply(value, scaling))
return out
def depth_ranking_loss(rendered_depth, gt_depth):
"""
Depth ranking loss as described in the SparseNeRF paper
Assumes that the layout of the batch comes from a PairPixelSampler, so that adjacent samples in the gt_depth
and rendered_depth are from pixels with a radius of each other
"""
m = 1e-4
dpt_diff = gt_depth[::2, :] - gt_depth[1::2, :]
out_diff = rendered_depth[::2, :] - rendered_depth[1::2, :] + m
differing_signs = torch.sign(dpt_diff) != torch.sign(out_diff)
return torch.nanmean((out_diff[differing_signs] * torch.sign(out_diff[differing_signs])))