mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-19 22:25:44 +08:00
Support downsample in dataset (#973)
* init * tests passing * pass through arguments * verbose * remove debug prints * switch to bilinear * update viewer * make parser outputs private * change name
This commit is contained in:
1 parent
aaaa2fa393
commit
a82d19f549
8 files changed
+64
-30
No files matched your search
@@ -21,17 +21,21 @@ import torch
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def get_image_mask_tensor_from_path(filepath: Path) -> torch.Tensor:
|
||||
def get_image_mask_tensor_from_path(filepath: Path, scale_factor: float = 1.0) -> torch.Tensor:
|
||||
"""
|
||||
Utility function to read a mask image from the given path and return a boolean tensor
|
||||
"""
|
||||
pil_mask = Image.open(filepath)
|
||||
if scale_factor != 1.0:
|
||||
width, height = pil_mask.size
|
||||
newsize = (int(width * scale_factor), int(height * scale_factor))
|
||||
pil_mask = pil_mask.resize(newsize, resample=Image.NEAREST)
|
||||
mask_tensor = torch.from_numpy(np.array(pil_mask)).unsqueeze(-1).bool()
|
||||
return mask_tensor
|
||||
|
||||
|
||||
def get_semantics_and_mask_tensors_from_path(
|
||||
filepath: Path, mask_indices: Union[List, torch.Tensor]
|
||||
filepath: Path, mask_indices: Union[List, torch.Tensor], scale_factor: float = 1.0
|
||||
) -> Tuple[torch.Tensor, torch.Tensor]:
|
||||
"""
|
||||
Utility function to read segmentation from the given filepath
|
||||
@@ -40,6 +44,10 @@ def get_semantics_and_mask_tensors_from_path(
|
||||
if isinstance(mask_indices, List):
|
||||
mask_indices = torch.tensor(mask_indices, dtype="int64").view(1, 1, -1)
|
||||
pil_image = Image.open(filepath)
|
||||
if scale_factor != 1.0:
|
||||
width, height = pil_image.size
|
||||
newsize = (int(width * scale_factor), int(height * scale_factor))
|
||||
pil_image = pil_image.resize(newsize, resample=Image.NEAREST)
|
||||
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
|
||||
Reference in new issue
Block a user