mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 07:05:44 +08:00
Refactor Data Pipeline (#896)
* add none check * black formatting * cleanup * cleanup * fix tests * remove new line * init * toy example working * semantic nerf working * simplify pixel samplers * cleanup + fix tests * comments * fix tests * fix tests
This commit is contained in:
1 parent
761645de05
commit
1a24f3e58c
19 files changed
+229
-197
No files matched your search
@@ -0,0 +1,45 @@
|
||||
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Utility functions to allow easy re-use of common operations across dataloaders"""
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple, Union
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def get_image_mask_tensor_from_path(filepath: Path) -> torch.Tensor:
|
||||
"""
|
||||
Utility function to read a mask image from the given path and return a boolean tensor
|
||||
"""
|
||||
pil_mask = Image.open(filepath)
|
||||
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]
|
||||
) -> Tuple[torch.Tensor, torch.Tensor]:
|
||||
"""
|
||||
Utility function to read segmentation from the given filepath
|
||||
If no mask is required - use mask_indices = []
|
||||
"""
|
||||
if isinstance(mask_indices, List):
|
||||
mask_indices = torch.tensor(mask_indices, dtype="int64").view(1, 1, -1)
|
||||
pil_image = Image.open(filepath)
|
||||
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