Depth supervision for Nerfacto (#1173)

* Implement depth supervision

* Fixes

* Change normalize dtype

* refactor

* Change depth weight

* Small refactor

* Change docstring

* Removu unused import

* Add assumption to depth comment

* Implement URF loss

* Remove default depth loss type param

* URF fixes

* Fix depth loss scale

* Visualize gt depths

* Fixes & documentation

* Documentation and formatting

* Fix formatting problems

* Fix linter problems

* Fix tests

* Fix tests
This commit is contained in:
Michal Pandy authored and GitHub committed 2023-01-02 10:13:38 +01:00
1 parent fa6f279751
commit 3da877050d
12 files changed
+460 -4

No files matched your search

+27
View File
@@ -16,6 +16,7 @@
from pathlib import Path
from typing import List, Tuple, Union
import cv2
import numpy as np
import torch
from PIL import Image
@@ -51,3 +52,29 @@ def get_semantics_and_mask_tensors_from_path(
semantics = torch.from_numpy(np.array(pil_image, dtype="int64"))[..., None]
mask = torch.sum(semantics == mask_indices, dim=-1, keepdim=True) == 0
return semantics, mask
def get_depth_image_from_path(
filepath: Path,
height: int,
width: int,
scale_factor: float,
interpolation: int = cv2.INTER_NEAREST,
) -> torch.Tensor:
"""Loads, rescales and resizes depth images.
Assumes filepath points to a 16-bit or 32-bit depth image.
Args:
filepath: Path to depth image.
height: Target depth image height.
width: Target depth image width.
scale_factor: Factor by which to scale depth image.
interpolation: Depth value interpolation for resizing.
Returns:
Depth image torch tensor with shape [width, height, 1].
"""
image = cv2.imread(str(filepath.absolute()), cv2.IMREAD_ANYDEPTH)
image = image.astype(np.float64) * scale_factor
image = cv2.resize(image, (width, height), interpolation=interpolation)
return torch.from_numpy(image[:, :, np.newaxis])