-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ethan/adding_normals
- Loading branch information
Showing
19 changed files
with
229 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
from dataclasses import dataclass, field | ||
from typing import Type | ||
|
||
from nerfstudio.data.datamanagers.base_datamanager import ( | ||
VanillaDataManager, | ||
VanillaDataManagerConfig, | ||
) | ||
from nerfstudio.data.datasets.semantic_dataset import SemanticDataset | ||
|
||
|
||
@dataclass | ||
class SemanticDataManagerConfig(VanillaDataManagerConfig): | ||
"""A semantic datamanager - required to use with .setup()""" | ||
|
||
_target: Type = field(default_factory=lambda: SemanticDataManager) | ||
|
||
|
||
class SemanticDataManager(VanillaDataManager): # pylint: disable=abstract-method | ||
"""Data manager implementation for data that also requires processing semantic data. | ||
Args: | ||
config: the DataManagerConfig used to instantiate class | ||
""" | ||
|
||
def create_train_dataset(self) -> SemanticDataset: | ||
return SemanticDataset(self.config.dataparser.setup().get_dataparser_outputs(split="train")) | ||
|
||
def create_eval_dataset(self) -> SemanticDataset: | ||
return SemanticDataset( | ||
self.config.dataparser.setup().get_dataparser_outputs(split="val" if not self.test_mode else "test") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
Oops, something went wrong.