Enable SparseNerf depth ranking loss to be used with GT/Sensor depth (#2312)

* add ranking loss to depth-nerfacto with GT depth

* formating

* pair pixel sampler bug fix from pr #2315

---------

Co-authored-by: Sasha Sax <asax@stanford.edu>
Co-authored-by: Ethan Weber <ethanweber@berkeley.edu>
Co-authored-by: AdamRashid96 <abrashid@berkeley.edu>
Co-authored-by: AdamRashid96 <71362382+AdamRashid96@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2023-08-26 02:56:52 -07:00
1 parent aaa6c3aa1d
commit 6e37b2b542
4 files changed
+50 -32

No files matched your search

+8 -7
View File
@@ -46,16 +46,20 @@ class DepthDataset(InputDataset):
def __init__(self, dataparser_outputs: DataparserOutputs, scale_factor: float = 1.0):
super().__init__(dataparser_outputs, scale_factor)
# if there are no depth images than we want to generate them all with zoe depth
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
if len(dataparser_outputs.image_filenames) > 0 and (
"depth_filenames" not in dataparser_outputs.metadata.keys()
or dataparser_outputs.metadata["depth_filenames"] is None
):
losses.DEPTH_METRIC = 0
CONSOLE.print("[bold yellow] No depth data found!")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
CONSOLE.print("[bold yellow] No depth data found! Generating pseudodepth...")
losses.FORCE_PSEUDODEPTH_LOSS = True
CONSOLE.print("[bold red] Using psueodepth: forcing depth loss to be ranking loss.")
cache = dataparser_outputs.image_filenames[0].parent / "depths.npy"
# Note: this should probably be saved to disk as images, and then loaded with the dataparser.
# That will allow multi-gpu training.
if cache.exists():
CONSOLE.print("[bold yellow] Loading cache!")
CONSOLE.print("[bold yellow] Loading pseudodata depth from cache!")
# load all the depths
self.depths = np.load(cache)
self.depths = torch.from_numpy(self.depths).to(device)
@@ -98,9 +102,6 @@ class DepthDataset(InputDataset):
self.metadata["depth_filenames"] = None
self.metadata["depth_unit_scale_factor"] = 1.0
else:
losses.DEPTH_METRIC = 0
self.depth_filenames = self.metadata["depth_filenames"]
self.depth_unit_scale_factor = self.metadata["depth_unit_scale_factor"]
+1 -1
View File
@@ -386,8 +386,8 @@ class PairPixelSampler(PixelSampler): # pylint: disable=too-few-public-methods
def __init__(self, config: PairPixelSamplerConfig, **kwargs) -> None:
self.config = config
self.radius = self.config.radius
self.rays_to_sample = self.config.num_rays_per_batch // 2
super().__init__(self.config, **kwargs)
self.rays_to_sample = self.config.num_rays_per_batch // 2
# overrides base method
def sample_method( # pylint: disable=no-self-use