mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 05:48:57 +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,49 @@
|
||||
# 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.
|
||||
|
||||
from typing import Dict
|
||||
|
||||
import torch
|
||||
|
||||
from nerfstudio.data.dataparsers.base_dataparser import DataparserOutputs, Semantics
|
||||
from nerfstudio.data.datasets.base_dataset import InputDataset
|
||||
from nerfstudio.data.utils.data_utils import get_semantics_and_mask_tensors_from_path
|
||||
|
||||
|
||||
class SemanticDataset(InputDataset):
|
||||
"""Dataset that returns images and semantics and masks.
|
||||
|
||||
Args:
|
||||
dataparser_outputs: description of where and how to read input images.
|
||||
"""
|
||||
|
||||
def __init__(self, dataparser_outputs: DataparserOutputs):
|
||||
super().__init__(dataparser_outputs)
|
||||
assert "semantics" in dataparser_outputs.metadata.keys() and isinstance(
|
||||
dataparser_outputs.metadata["semantics"], Semantics
|
||||
)
|
||||
self.semantics = dataparser_outputs.metadata["semantics"]
|
||||
self.mask_indices = torch.tensor(
|
||||
[self.semantics.classes.index(mask_class) for mask_class in self.semantics.mask_classes]
|
||||
).view(1, 1, -1)
|
||||
|
||||
def get_metadata(self, data: Dict) -> Dict:
|
||||
# handle mask
|
||||
filepath = self.semantics.filenames[data["image_idx"]]
|
||||
semantic_label, mask = get_semantics_and_mask_tensors_from_path(
|
||||
filepath=filepath, mask_indices=self.mask_indices
|
||||
)
|
||||
if "mask" in data.keys():
|
||||
mask = mask & data["mask"]
|
||||
return {"mask": mask, "semantics": semantic_label}
|
||||
Reference in new issue
Block a user