mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-02 22:08:41 +08:00
1 parent
9d15ba6a2a
commit
c20fed83bb
61 files changed
+226
-332
No files matched your search
@@ -185,3 +185,4 @@ bash/
|
|||||||
cache/
|
cache/
|
||||||
renders/
|
renders/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
camera_paths/
|
||||||
@@ -73,7 +73,7 @@ NeRFs are a volumetric representation encoded into a neural network. They are no
|
|||||||
The associated NeRF fields can be instantiated with the following nerfstudio code (encoding described in next section):
|
The associated NeRF fields can be instantiated with the following nerfstudio code (encoding described in next section):
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
|
|
||||||
field_coarse = NeRFField(position_encoding=pos_enc, direction_encoding=dir_enc)
|
field_coarse = NeRFField(position_encoding=pos_enc, direction_encoding=dir_enc)
|
||||||
field_fine = NeRFField(position_encoding=pos_enc, direction_encoding=dir_enc)
|
field_fine = NeRFField(position_encoding=pos_enc, direction_encoding=dir_enc)
|
||||||
@@ -84,7 +84,7 @@ field_fine = NeRFField(position_encoding=pos_enc, direction_encoding=dir_enc)
|
|||||||
An extra trick is necessary to make the neural network expressive enough to represent fine details in the scene. The input coordinates $(x,y,z,\theta,\phi)$ need to be encoded to a higher dimensional space prior to being input into the network. You can learn more about encodings [here](../model_components/visualize_encoders.ipynb).
|
An extra trick is necessary to make the neural network expressive enough to represent fine details in the scene. The input coordinates $(x,y,z,\theta,\phi)$ need to be encoded to a higher dimensional space prior to being input into the network. You can learn more about encodings [here](../model_components/visualize_encoders.ipynb).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from nerfstudio.field_components.encoding import NeRFEncoding
|
from nerfstudio.field_components.encodings import NeRFEncoding
|
||||||
|
|
||||||
pos_enc = NeRFEncoding(
|
pos_enc = NeRFEncoding(
|
||||||
in_dim=3, num_frequencies=10, min_freq_exp=0.0, max_freq_exp=8.0, include_input=True
|
in_dim=3, num_frequencies=10, min_freq_exp=0.0, max_freq_exp=8.0, include_input=True
|
||||||
@@ -142,7 +142,7 @@ How we sample points along rays in space is an important design decision. Variou
|
|||||||
Associated code:
|
Associated code:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from nerfstudio.model_components.ray_sampler import PDFSampler, UniformSampler
|
from nerfstudio.model_components.ray_samplers import PDFSampler, UniformSampler
|
||||||
|
|
||||||
sampler_uniform = UniformSampler(num_samples=num_coarse_samples)
|
sampler_uniform = UniformSampler(num_samples=num_coarse_samples)
|
||||||
ray_samples_uniform = sampler_uniform(ray_bundle)
|
ray_samples_uniform = sampler_uniform(ray_bundle)
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
Encodings
|
Encodings
|
||||||
===================
|
===================
|
||||||
|
|
||||||
.. automodule:: nerfstudio.field_components.encoding
|
.. automodule:: nerfstudio.field_components.encodings
|
||||||
:members:
|
:members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
.. _field_losses:
|
|
||||||
|
|
||||||
Field Losses
|
|
||||||
===================
|
|
||||||
|
|
||||||
.. automodule:: nerfstudio.field_components.field_losses
|
|
||||||
:members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -10,6 +10,5 @@ TODO: High level description of field modules and how they connect together.
|
|||||||
encodings
|
encodings
|
||||||
embeddings
|
embeddings
|
||||||
field_heads
|
field_heads
|
||||||
field_losses
|
|
||||||
mlp
|
mlp
|
||||||
spatial_distortions
|
spatial_distortions
|
||||||
@@ -17,9 +17,9 @@ Instant NGP
|
|||||||
:members:
|
:members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
NeRF
|
Vanilla NeRF
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
.. automodule:: nerfstudio.fields.nerf_field
|
.. automodule:: nerfstudio.fields.vanilla_nerf_field
|
||||||
:members:
|
:members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
.. _graph_modules:
|
.. _graph_modules:
|
||||||
|
|
||||||
Graph Modules
|
Model Components
|
||||||
===================
|
===================
|
||||||
|
|
||||||
TODO: High level description of graph modules and how they are used.
|
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
|
||||||
ray_sampler
|
ray_sampler
|
||||||
ray_losses
|
losses
|
||||||
renderers
|
renderers
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
.. _losses:
|
||||||
|
|
||||||
|
Losses
|
||||||
|
===================
|
||||||
|
|
||||||
|
.. automodule:: nerfstudio.model_components.losses
|
||||||
|
:members:
|
||||||
|
:show-inheritance:
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
.. _ray_losses:
|
|
||||||
|
|
||||||
Ray Losses
|
|
||||||
===================
|
|
||||||
|
|
||||||
.. automodule:: nerfstudio.model_components.ray_losses
|
|
||||||
:members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -3,6 +3,6 @@
|
|||||||
Ray Sampler
|
Ray Sampler
|
||||||
===================
|
===================
|
||||||
|
|
||||||
.. automodule:: nerfstudio.model_components.ray_sampler
|
.. automodule:: nerfstudio.model_components.ray_samplers
|
||||||
:members:
|
:members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
.. _graphs:
|
.. _graphs:
|
||||||
|
|
||||||
Graphs
|
Models
|
||||||
============
|
============
|
||||||
|
|
||||||
Base
|
Base
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
.. automodule:: nerfstudio.models.base
|
.. automodule:: nerfstudio.models.base_model
|
||||||
:members:
|
:members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
.. _colormaps:
|
||||||
|
|
||||||
|
Colormaps
|
||||||
|
----------------
|
||||||
|
|
||||||
|
.. automodule:: nerfstudio.utils.colormaps
|
||||||
|
:members:
|
||||||
|
:show-inheritance:
|
||||||
@@ -7,5 +7,5 @@ Utils
|
|||||||
|
|
||||||
colors
|
colors
|
||||||
math
|
math
|
||||||
visualization
|
colormaps
|
||||||
tensor_dataclass
|
tensor_dataclass
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
.. _visualization:
|
|
||||||
|
|
||||||
Visualization
|
|
||||||
----------------
|
|
||||||
|
|
||||||
.. automodule:: nerfstudio.utils.visualization
|
|
||||||
:members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
"from nerfstudio.data.base import DataManager\n",
|
"from nerfstudio.data.base import DataManager\n",
|
||||||
"from nerfstudio.data.structs import DatasetInputs\n",
|
"from nerfstudio.data.structs import DatasetInputs\n",
|
||||||
"from nerfstudio.models.base import Model\n",
|
"from nerfstudio.models.base import Model\n",
|
||||||
"from nerfstudio.pipelines.base import Pipeline\n",
|
"from nerfstudio.pipelines.base_pipeline import Pipeline\n",
|
||||||
"from nerfstudio.models.instant_ngp import NGPModel\n",
|
"from nerfstudio.models.instant_ngp import NGPModel\n",
|
||||||
"from nerfstudio.cameras.rays import RayBundle"
|
"from nerfstudio.cameras.rays import RayBundle"
|
||||||
]
|
]
|
||||||
@@ -292,7 +292,7 @@
|
|||||||
"pprint.pprint(pipeline_config)\n",
|
"pprint.pprint(pipeline_config)\n",
|
||||||
"print(\"----------------------------------------------------\")\n",
|
"print(\"----------------------------------------------------\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# from nerfstudio.pipelines.base import setup_pipeline\n",
|
"# from nerfstudio.pipelines.base_pipeline import setup_pipeline\n",
|
||||||
"# pipeline = setup_pipeline(pipeline_config, device=\"cuda\")\n",
|
"# pipeline = setup_pipeline(pipeline_config, device=\"cuda\")\n",
|
||||||
"pipeline = pipeline_config.setup()"
|
"pipeline = pipeline_config.setup()"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ class ViewerConfig(PrintableConfig):
|
|||||||
|
|
||||||
from nerfstudio.engine.optimizers import OptimizerConfig
|
from nerfstudio.engine.optimizers import OptimizerConfig
|
||||||
from nerfstudio.engine.schedulers import SchedulerConfig
|
from nerfstudio.engine.schedulers import SchedulerConfig
|
||||||
from nerfstudio.pipelines.base import VanillaPipelineConfig
|
from nerfstudio.pipelines.base_pipeline import VanillaPipelineConfig
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from nerfstudio.data.dataparsers.friends_dataparser import FriendsDataParserConf
|
|||||||
from nerfstudio.data.dataparsers.mipnerf_dataparser import MipNerf360DataParserConfig
|
from nerfstudio.data.dataparsers.mipnerf_dataparser import MipNerf360DataParserConfig
|
||||||
from nerfstudio.engine.optimizers import AdamOptimizerConfig, RAdamOptimizerConfig
|
from nerfstudio.engine.optimizers import AdamOptimizerConfig, RAdamOptimizerConfig
|
||||||
from nerfstudio.engine.schedulers import SchedulerConfig
|
from nerfstudio.engine.schedulers import SchedulerConfig
|
||||||
from nerfstudio.models.base import VanillaModelConfig
|
from nerfstudio.models.base_model import VanillaModelConfig
|
||||||
from nerfstudio.models.instant_ngp import InstantNGPModelConfig
|
from nerfstudio.models.instant_ngp import InstantNGPModelConfig
|
||||||
from nerfstudio.models.mipnerf import MipNerfModel
|
from nerfstudio.models.mipnerf import MipNerfModel
|
||||||
from nerfstudio.models.mipnerf_360 import MipNerf360Model
|
from nerfstudio.models.mipnerf_360 import MipNerf360Model
|
||||||
@@ -38,7 +38,7 @@ from nerfstudio.models.nerfw import NerfWModelConfig
|
|||||||
from nerfstudio.models.semantic_nerf import SemanticNerfModel
|
from nerfstudio.models.semantic_nerf import SemanticNerfModel
|
||||||
from nerfstudio.models.tensorf import TensoRFModelConfig
|
from nerfstudio.models.tensorf import TensoRFModelConfig
|
||||||
from nerfstudio.models.vanilla_nerf import NeRFModel
|
from nerfstudio.models.vanilla_nerf import NeRFModel
|
||||||
from nerfstudio.pipelines.base import VanillaPipelineConfig
|
from nerfstudio.pipelines.base_pipeline import VanillaPipelineConfig
|
||||||
from nerfstudio.pipelines.dynamic_batch import DynamicBatchPipelineConfig
|
from nerfstudio.pipelines.dynamic_batch import DynamicBatchPipelineConfig
|
||||||
|
|
||||||
model_configs: Dict[str, Config] = {}
|
model_configs: Dict[str, Config] = {}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ from nerfstudio.data.utils.dataloaders import (
|
|||||||
RandIndicesEvalDataloader,
|
RandIndicesEvalDataloader,
|
||||||
)
|
)
|
||||||
from nerfstudio.data.utils.datasets import InputDataset
|
from nerfstudio.data.utils.datasets import InputDataset
|
||||||
from nerfstudio.model_components.ray_generator import RayGenerator
|
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
|
||||||
from nerfstudio.utils.callbacks import TrainingCallback, TrainingCallbackAttributes
|
from nerfstudio.model_components.ray_generators import RayGenerator
|
||||||
from nerfstudio.utils.misc import IterableWrapper
|
from nerfstudio.utils.misc import IterableWrapper
|
||||||
|
|
||||||
AnnotatedDataParserUnion = dcargs.extras.subcommand_type_from_defaults(
|
AnnotatedDataParserUnion = dcargs.extras.subcommand_type_from_defaults(
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ from torch.utils.data import Dataset
|
|||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.data.dataparsers.base_dataparser import DataparserOutputs
|
from nerfstudio.data.dataparsers.base_dataparser import DataparserOutputs
|
||||||
from nerfstudio.utils.misc import is_not_none
|
|
||||||
|
|
||||||
|
|
||||||
class InputDataset(Dataset):
|
class InputDataset(Dataset):
|
||||||
@@ -80,7 +79,6 @@ class InputDataset(Dataset):
|
|||||||
"""
|
"""
|
||||||
image = self.get_image(image_idx)
|
image = self.get_image(image_idx)
|
||||||
data = {"image_idx": image_idx}
|
data = {"image_idx": image_idx}
|
||||||
assert is_not_none(image)
|
|
||||||
data["image"] = image
|
data["image"] = image
|
||||||
for _, data_func_dict in self.dataset_inputs.additional_inputs.items():
|
for _, data_func_dict in self.dataset_inputs.additional_inputs.items():
|
||||||
assert "func" in data_func_dict, "Missing function to process data: specify `func` in `additional_inputs`"
|
assert "func" in data_func_dict, "Missing function to process data: specify `func` in `additional_inputs`"
|
||||||
|
|||||||
File renamed without changes.
@@ -29,14 +29,14 @@ from rich import console
|
|||||||
from torch.cuda.amp.grad_scaler import GradScaler
|
from torch.cuda.amp.grad_scaler import GradScaler
|
||||||
|
|
||||||
from nerfstudio.configs import base_config as cfg
|
from nerfstudio.configs import base_config as cfg
|
||||||
from nerfstudio.engine.optimizers import Optimizers, setup_optimizers
|
from nerfstudio.engine.callbacks import (
|
||||||
from nerfstudio.pipelines.base import VanillaPipeline
|
|
||||||
from nerfstudio.utils import profiler, writer
|
|
||||||
from nerfstudio.utils.callbacks import (
|
|
||||||
TrainingCallback,
|
TrainingCallback,
|
||||||
TrainingCallbackAttributes,
|
TrainingCallbackAttributes,
|
||||||
TrainingCallbackLocation,
|
TrainingCallbackLocation,
|
||||||
)
|
)
|
||||||
|
from nerfstudio.engine.optimizers import Optimizers, setup_optimizers
|
||||||
|
from nerfstudio.pipelines.base_pipeline import VanillaPipeline
|
||||||
|
from nerfstudio.utils import profiler, writer
|
||||||
from nerfstudio.utils.decorators import (
|
from nerfstudio.utils.decorators import (
|
||||||
check_eval_enabled,
|
check_eval_enabled,
|
||||||
check_main_thread,
|
check_main_thread,
|
||||||
|
|||||||
@@ -13,6 +13,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""init field modules"""
|
"""init field modules"""
|
||||||
from .base import FieldModule
|
from .base_field_component import FieldComponent
|
||||||
from .encoding import Encoding, ScalingAndOffset
|
from .encodings import Encoding, ScalingAndOffset
|
||||||
from .mlp import MLP
|
from .mlp import MLP
|
||||||
+1
-1
@@ -22,7 +22,7 @@ from torch import nn
|
|||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
|
|
||||||
class FieldModule(nn.Module):
|
class FieldComponent(nn.Module):
|
||||||
"""Field modules that can be combined to store and compute the fields.
|
"""Field modules that can be combined to store and compute the fields.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -20,10 +20,10 @@ Code for embeddings.
|
|||||||
import torch
|
import torch
|
||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.field_components.base import FieldModule
|
from nerfstudio.field_components.base_field_component import FieldComponent
|
||||||
|
|
||||||
|
|
||||||
class Embedding(FieldModule):
|
class Embedding(FieldComponent):
|
||||||
"""Index into embeddings.
|
"""Index into embeddings.
|
||||||
# TODO: add different types of initializations
|
# TODO: add different types of initializations
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ import torch.nn.functional as F
|
|||||||
from torch import nn
|
from torch import nn
|
||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.field_components.base import FieldModule
|
from nerfstudio.field_components.base_field_component import FieldComponent
|
||||||
from nerfstudio.utils.comments import print_tcnn_speed_warning
|
|
||||||
from nerfstudio.utils.math import components_from_spherical_harmonics, expected_sin
|
from nerfstudio.utils.math import components_from_spherical_harmonics, expected_sin
|
||||||
|
from nerfstudio.utils.printing import print_tcnn_speed_warning
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import tinycudann as tcnn
|
import tinycudann as tcnn
|
||||||
@@ -37,7 +37,7 @@ except ImportError:
|
|||||||
TCNN_EXISTS = False
|
TCNN_EXISTS = False
|
||||||
|
|
||||||
|
|
||||||
class Encoding(FieldModule):
|
class Encoding(FieldComponent):
|
||||||
"""Encode an input tensor. Intended to be subclassed
|
"""Encode an input tensor. Intended to be subclassed
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -21,7 +21,7 @@ from typing import Callable, Optional, Union
|
|||||||
from torch import nn
|
from torch import nn
|
||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.field_components.base import FieldModule
|
from nerfstudio.field_components.base_field_component import FieldComponent
|
||||||
|
|
||||||
|
|
||||||
class FieldHeadNames(Enum):
|
class FieldHeadNames(Enum):
|
||||||
@@ -36,7 +36,7 @@ class FieldHeadNames(Enum):
|
|||||||
SEMANTICS = "semantics"
|
SEMANTICS = "semantics"
|
||||||
|
|
||||||
|
|
||||||
class FieldHead(FieldModule):
|
class FieldHead(FieldComponent):
|
||||||
"""Base field output
|
"""Base field output
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
# Copyright 2022 The Plenoptix 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.
|
|
||||||
@@ -21,10 +21,10 @@ import torch
|
|||||||
from torch import nn
|
from torch import nn
|
||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.field_components.base import FieldModule
|
from nerfstudio.field_components.base_field_component import FieldComponent
|
||||||
|
|
||||||
|
|
||||||
class MLP(FieldModule):
|
class MLP(FieldComponent):
|
||||||
"""Multilayer perceptron
|
"""Multilayer perceptron
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from nerfstudio.cameras.rays import RaySamples
|
|||||||
from nerfstudio.data.scene_box import SceneBox
|
from nerfstudio.data.scene_box import SceneBox
|
||||||
from nerfstudio.field_components.activations import trunc_exp
|
from nerfstudio.field_components.activations import trunc_exp
|
||||||
from nerfstudio.field_components.embedding import Embedding
|
from nerfstudio.field_components.embedding import Embedding
|
||||||
from nerfstudio.field_components.encoding import Encoding, HashEncoding, SHEncoding
|
from nerfstudio.field_components.encodings import Encoding, HashEncoding, SHEncoding
|
||||||
from nerfstudio.field_components.field_heads import (
|
from nerfstudio.field_components.field_heads import (
|
||||||
DensityFieldHead,
|
DensityFieldHead,
|
||||||
FieldHead,
|
FieldHead,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from torchtyping import TensorType
|
|||||||
|
|
||||||
from nerfstudio.cameras.rays import RaySamples
|
from nerfstudio.cameras.rays import RaySamples
|
||||||
from nerfstudio.field_components.embedding import Embedding
|
from nerfstudio.field_components.embedding import Embedding
|
||||||
from nerfstudio.field_components.encoding import Encoding, Identity
|
from nerfstudio.field_components.encodings import Encoding, Identity
|
||||||
from nerfstudio.field_components.field_heads import (
|
from nerfstudio.field_components.field_heads import (
|
||||||
DensityFieldHead,
|
DensityFieldHead,
|
||||||
FieldHeadNames,
|
FieldHeadNames,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from torch import nn
|
|||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RaySamples
|
from nerfstudio.cameras.rays import RaySamples
|
||||||
from nerfstudio.field_components.encoding import Encoding, Identity
|
from nerfstudio.field_components.encodings import Encoding, Identity
|
||||||
from nerfstudio.field_components.field_heads import (
|
from nerfstudio.field_components.field_heads import (
|
||||||
DensityFieldHead,
|
DensityFieldHead,
|
||||||
FieldHeadNames,
|
FieldHeadNames,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from torch import nn
|
|||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RaySamples
|
from nerfstudio.cameras.rays import RaySamples
|
||||||
from nerfstudio.field_components.encoding import Encoding, Identity
|
from nerfstudio.field_components.encodings import Encoding, Identity
|
||||||
from nerfstudio.field_components.field_heads import (
|
from nerfstudio.field_components.field_heads import (
|
||||||
DensityFieldHead,
|
DensityFieldHead,
|
||||||
FieldHead,
|
FieldHead,
|
||||||
@@ -20,6 +20,8 @@ import torch
|
|||||||
from torch import nn
|
from torch import nn
|
||||||
from torchtyping import TensorType
|
from torchtyping import TensorType
|
||||||
|
|
||||||
|
from nerfstudio.cameras.rays import RaySamples
|
||||||
|
|
||||||
L1Loss = nn.L1Loss
|
L1Loss = nn.L1Loss
|
||||||
MSELoss = nn.MSELoss
|
MSELoss = nn.MSELoss
|
||||||
|
|
||||||
@@ -137,3 +139,45 @@ def distortion_loss(weights_list, ray_samples_list):
|
|||||||
w = weights_list[-1][..., 0]
|
w = weights_list[-1][..., 0]
|
||||||
loss = torch.mean(lossfun_distortion(c, w))
|
loss = torch.mean(lossfun_distortion(c, w))
|
||||||
return loss
|
return loss
|
||||||
|
|
||||||
|
|
||||||
|
def nerfstudio_distortion_loss(
|
||||||
|
ray_samples: RaySamples,
|
||||||
|
densities: TensorType["bs":..., "num_samples", 1] = None,
|
||||||
|
weights: TensorType["bs":..., "num_samples", 1] = None,
|
||||||
|
) -> TensorType["bs":..., 1]:
|
||||||
|
"""Ray based distortion loss proposed in MipNeRF-360. Returns distortion Loss.
|
||||||
|
|
||||||
|
.. math::
|
||||||
|
|
||||||
|
\\mathcal{L}(\\mathbf{s}, \\mathbf{w}) =\\iint\\limits_{-\\infty}^{\\,\\,\\,\\infty}
|
||||||
|
\\mathbf{w}_\\mathbf{s}(u)\\mathbf{w}_\\mathbf{s}(v)|u - v|\\,d_{u}\\,d_{v}
|
||||||
|
|
||||||
|
where :math:`\\mathbf{w}_\\mathbf{s}(u)=\\sum_i w_i \\mathbb{1}_{[\\mathbf{s}_i, \\mathbf{s}_{i+1})}(u)`
|
||||||
|
is the weight at location :math:`u` between bin locations :math:`s_i` and :math:`s_{i+1}`.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ray_samples: Ray samples to compute loss over
|
||||||
|
densities: Predicted sample densities
|
||||||
|
weights: Predicted weights from densities and sample locations
|
||||||
|
"""
|
||||||
|
if torch.is_tensor(densities):
|
||||||
|
assert not torch.is_tensor(weights), "Cannot use both densities and weights"
|
||||||
|
# Compute the weight at each sample location
|
||||||
|
weights = ray_samples.get_weights(densities)
|
||||||
|
if torch.is_tensor(weights):
|
||||||
|
assert not torch.is_tensor(densities), "Cannot use both densities and weights"
|
||||||
|
|
||||||
|
starts = ray_samples.spacing_starts
|
||||||
|
ends = ray_samples.spacing_ends
|
||||||
|
|
||||||
|
assert starts is not None and ends is not None, "Ray samples must have spacing starts and ends"
|
||||||
|
midpoints = (starts + ends) / 2.0 # (..., num_samples, 1)
|
||||||
|
|
||||||
|
loss = (
|
||||||
|
weights * weights[..., None, :, 0] * torch.abs(midpoints - midpoints[..., None, :, 0])
|
||||||
|
) # (..., num_samples, num_samples)
|
||||||
|
loss = torch.sum(loss, dim=(-1, -2))[..., None] # (..., num_samples)
|
||||||
|
loss = loss + 1 / 3.0 * torch.sum(weights**2 * (ends - starts), dim=-2)
|
||||||
|
|
||||||
|
return loss
|
||||||
File renamed without changes.
@@ -1,62 +0,0 @@
|
|||||||
# Copyright 2022 The Plenoptix 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.
|
|
||||||
|
|
||||||
"""Collection of Ray Losses"""
|
|
||||||
|
|
||||||
import torch
|
|
||||||
from torchtyping import TensorType
|
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RaySamples
|
|
||||||
|
|
||||||
|
|
||||||
def distortion_loss(
|
|
||||||
ray_samples: RaySamples,
|
|
||||||
densities: TensorType["bs":..., "num_samples", 1] = None,
|
|
||||||
weights: TensorType["bs":..., "num_samples", 1] = None,
|
|
||||||
) -> TensorType["bs":..., 1]:
|
|
||||||
"""Ray based distortion loss proposed in MipNeRF-360. Returns distortion Loss.
|
|
||||||
|
|
||||||
.. math::
|
|
||||||
|
|
||||||
\\mathcal{L}(\\mathbf{s}, \\mathbf{w}) =\\iint\\limits_{-\\infty}^{\\,\\,\\,\\infty}
|
|
||||||
\\mathbf{w}_\\mathbf{s}(u)\\mathbf{w}_\\mathbf{s}(v)|u - v|\\,d_{u}\\,d_{v}
|
|
||||||
|
|
||||||
where :math:`\\mathbf{w}_\\mathbf{s}(u)=\\sum_i w_i \\mathbb{1}_{[\\mathbf{s}_i, \\mathbf{s}_{i+1})}(u)`
|
|
||||||
is the weight at location :math:`u` between bin locations :math:`s_i` and :math:`s_{i+1}`.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
ray_samples: Ray samples to compute loss over
|
|
||||||
densities: Predicted sample densities
|
|
||||||
weights: Predicted weights from densities and sample locations
|
|
||||||
"""
|
|
||||||
if torch.is_tensor(densities):
|
|
||||||
assert not torch.is_tensor(weights), "Cannot use both densities and weights"
|
|
||||||
# Compute the weight at each sample location
|
|
||||||
weights = ray_samples.get_weights(densities)
|
|
||||||
if torch.is_tensor(weights):
|
|
||||||
assert not torch.is_tensor(densities), "Cannot use both densities and weights"
|
|
||||||
|
|
||||||
starts = ray_samples.spacing_starts
|
|
||||||
ends = ray_samples.spacing_ends
|
|
||||||
|
|
||||||
assert starts is not None and ends is not None, "Ray samples must have spacing starts and ends"
|
|
||||||
midpoints = (starts + ends) / 2.0 # (..., num_samples, 1)
|
|
||||||
|
|
||||||
loss = (
|
|
||||||
weights * weights[..., None, :, 0] * torch.abs(midpoints - midpoints[..., None, :, 0])
|
|
||||||
) # (..., num_samples, num_samples)
|
|
||||||
loss = torch.sum(loss, dim=(-1, -2))[..., None] # (..., num_samples)
|
|
||||||
loss = loss + 1 / 3.0 * torch.sum(weights**2 * (ends - starts), dim=-2)
|
|
||||||
|
|
||||||
return loss
|
|
||||||
File renamed without changes.
@@ -31,8 +31,8 @@ from nerfstudio.cameras.rays import RayBundle
|
|||||||
from nerfstudio.configs.base_config import InstantiateConfig
|
from nerfstudio.configs.base_config import InstantiateConfig
|
||||||
from nerfstudio.configs.config_utils import to_immutable_dict
|
from nerfstudio.configs.config_utils import to_immutable_dict
|
||||||
from nerfstudio.data.scene_box import SceneBox
|
from nerfstudio.data.scene_box import SceneBox
|
||||||
|
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
|
||||||
from nerfstudio.model_components.scene_colliders import NearFarCollider
|
from nerfstudio.model_components.scene_colliders import NearFarCollider
|
||||||
from nerfstudio.utils.callbacks import TrainingCallback, TrainingCallbackAttributes
|
|
||||||
|
|
||||||
|
|
||||||
# Model related configs
|
# Model related configs
|
||||||
@@ -30,22 +30,22 @@ from torchmetrics.functional import structural_similarity_index_measure
|
|||||||
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
|
from nerfstudio.engine.callbacks import (
|
||||||
|
TrainingCallback,
|
||||||
|
TrainingCallbackAttributes,
|
||||||
|
TrainingCallbackLocation,
|
||||||
|
)
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.fields.instant_ngp_field import TCNNInstantNGPField
|
from nerfstudio.fields.instant_ngp_field import TCNNInstantNGPField
|
||||||
from nerfstudio.model_components.loss import MSELoss
|
from nerfstudio.model_components.losses import MSELoss
|
||||||
from nerfstudio.model_components.ray_sampler import VolumetricSampler
|
from nerfstudio.model_components.ray_samplers import VolumetricSampler
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.models.base import Model, ModelConfig
|
from nerfstudio.models.base_model import Model, ModelConfig
|
||||||
from nerfstudio.utils import colors, visualization
|
from nerfstudio.utils import colormaps, colors
|
||||||
from nerfstudio.utils.callbacks import (
|
|
||||||
TrainingCallback,
|
|
||||||
TrainingCallbackAttributes,
|
|
||||||
TrainingCallbackLocation,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -223,12 +223,12 @@ class NGPModel(Model):
|
|||||||
|
|
||||||
image = batch["image"].to(self.device)
|
image = batch["image"].to(self.device)
|
||||||
rgb = outputs["rgb"]
|
rgb = outputs["rgb"]
|
||||||
acc = visualization.apply_colormap(outputs["accumulation"])
|
acc = colormaps.apply_colormap(outputs["accumulation"])
|
||||||
depth = visualization.apply_depth_colormap(
|
depth = colormaps.apply_depth_colormap(
|
||||||
outputs["depth"],
|
outputs["depth"],
|
||||||
accumulation=outputs["accumulation"],
|
accumulation=outputs["accumulation"],
|
||||||
)
|
)
|
||||||
alive_ray_mask = visualization.apply_colormap(outputs["alive_ray_mask"])
|
alive_ray_mask = colormaps.apply_colormap(outputs["alive_ray_mask"])
|
||||||
|
|
||||||
combined_rgb = torch.cat([image, rgb], dim=1)
|
combined_rgb = torch.cat([image, rgb], dim=1)
|
||||||
combined_acc = torch.cat([acc], dim=1)
|
combined_acc = torch.cat([acc], dim=1)
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ from torchmetrics.functional import structural_similarity_index_measure
|
|||||||
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.field_components.encoding import NeRFEncoding
|
from nerfstudio.field_components.encodings import NeRFEncoding
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
from nerfstudio.model_components.loss import MSELoss
|
from nerfstudio.model_components.losses import MSELoss
|
||||||
from nerfstudio.model_components.ray_sampler import PDFSampler, UniformSampler
|
from nerfstudio.model_components.ray_samplers import PDFSampler, UniformSampler
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.models.base import Model, ModelConfig
|
from nerfstudio.models.base_model import Model, ModelConfig
|
||||||
from nerfstudio.utils import colors, misc, visualization
|
from nerfstudio.utils import colormaps, colors, misc
|
||||||
|
|
||||||
|
|
||||||
class MipNerfModel(Model):
|
class MipNerfModel(Model):
|
||||||
@@ -150,15 +150,15 @@ class MipNerfModel(Model):
|
|||||||
image = batch["image"].to(outputs["rgb_coarse"].device)
|
image = batch["image"].to(outputs["rgb_coarse"].device)
|
||||||
rgb_coarse = outputs["rgb_coarse"]
|
rgb_coarse = outputs["rgb_coarse"]
|
||||||
rgb_fine = outputs["rgb_fine"]
|
rgb_fine = outputs["rgb_fine"]
|
||||||
acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"])
|
acc_coarse = colormaps.apply_colormap(outputs["accumulation_coarse"])
|
||||||
acc_fine = visualization.apply_colormap(outputs["accumulation_fine"])
|
acc_fine = colormaps.apply_colormap(outputs["accumulation_fine"])
|
||||||
depth_coarse = visualization.apply_depth_colormap(
|
depth_coarse = colormaps.apply_depth_colormap(
|
||||||
outputs["depth_coarse"],
|
outputs["depth_coarse"],
|
||||||
accumulation=outputs["accumulation_coarse"],
|
accumulation=outputs["accumulation_coarse"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
far_plane=self.config.collider_params["far_plane"],
|
far_plane=self.config.collider_params["far_plane"],
|
||||||
)
|
)
|
||||||
depth_fine = visualization.apply_depth_colormap(
|
depth_fine = colormaps.apply_depth_colormap(
|
||||||
outputs["depth_fine"],
|
outputs["depth_fine"],
|
||||||
accumulation=outputs["accumulation_fine"],
|
accumulation=outputs["accumulation_fine"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
|
|||||||
@@ -27,20 +27,19 @@ from torchmetrics.functional import structural_similarity_index_measure
|
|||||||
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.field_components.encoding import NeRFEncoding
|
from nerfstudio.field_components.encodings import NeRFEncoding
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.field_components.spatial_distortions import SceneContraction
|
from nerfstudio.field_components.spatial_distortions import SceneContraction
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
from nerfstudio.model_components.loss import MSELoss
|
from nerfstudio.model_components.losses import MSELoss, distortion_loss
|
||||||
from nerfstudio.model_components.ray_losses import distortion_loss
|
from nerfstudio.model_components.ray_samplers import PDFSampler, UniformSampler
|
||||||
from nerfstudio.model_components.ray_sampler import PDFSampler, UniformSampler
|
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.models.base import Model, ModelConfig
|
from nerfstudio.models.base_model import Model, ModelConfig
|
||||||
from nerfstudio.utils import colors, misc, visualization
|
from nerfstudio.utils import colormaps, colors, misc
|
||||||
|
|
||||||
|
|
||||||
class MipNerf360Model(Model):
|
class MipNerf360Model(Model):
|
||||||
@@ -165,15 +164,15 @@ class MipNerf360Model(Model):
|
|||||||
image = batch["image"].to(outputs["rgb_coarse"].device)
|
image = batch["image"].to(outputs["rgb_coarse"].device)
|
||||||
rgb_coarse = outputs["rgb_coarse"]
|
rgb_coarse = outputs["rgb_coarse"]
|
||||||
rgb_fine = outputs["rgb_fine"]
|
rgb_fine = outputs["rgb_fine"]
|
||||||
acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"])
|
acc_coarse = colormaps.apply_colormap(outputs["accumulation_coarse"])
|
||||||
acc_fine = visualization.apply_colormap(outputs["accumulation_fine"])
|
acc_fine = colormaps.apply_colormap(outputs["accumulation_fine"])
|
||||||
depth_coarse = visualization.apply_depth_colormap(
|
depth_coarse = colormaps.apply_depth_colormap(
|
||||||
outputs["depth_coarse"],
|
outputs["depth_coarse"],
|
||||||
accumulation=outputs["accumulation_coarse"],
|
accumulation=outputs["accumulation_coarse"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
far_plane=self.config.collider_params["far_plane"],
|
far_plane=self.config.collider_params["far_plane"],
|
||||||
)
|
)
|
||||||
depth_fine = visualization.apply_depth_colormap(
|
depth_fine = colormaps.apply_depth_colormap(
|
||||||
outputs["depth_fine"],
|
outputs["depth_fine"],
|
||||||
accumulation=outputs["accumulation_fine"],
|
accumulation=outputs["accumulation_fine"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
|
|||||||
@@ -29,25 +29,25 @@ from torchmetrics.functional import structural_similarity_index_measure
|
|||||||
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
|
from nerfstudio.engine.callbacks import (
|
||||||
|
TrainingCallback,
|
||||||
|
TrainingCallbackAttributes,
|
||||||
|
TrainingCallbackLocation,
|
||||||
|
)
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.field_components.spatial_distortions import SceneContraction
|
from nerfstudio.field_components.spatial_distortions import SceneContraction
|
||||||
from nerfstudio.fields.density_fields import HashMLPDensityField
|
from nerfstudio.fields.density_fields import HashMLPDensityField
|
||||||
from nerfstudio.fields.nerfacto_field import TCNNNerfactoField
|
from nerfstudio.fields.nerfacto_field import TCNNNerfactoField
|
||||||
from nerfstudio.model_components.loss import MSELoss, distortion_loss, interlevel_loss
|
from nerfstudio.model_components.losses import MSELoss, distortion_loss, interlevel_loss
|
||||||
from nerfstudio.model_components.ray_sampler import ProposalNetworkSampler
|
from nerfstudio.model_components.ray_samplers import ProposalNetworkSampler
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.model_components.scene_colliders import NearFarCollider
|
from nerfstudio.model_components.scene_colliders import NearFarCollider
|
||||||
from nerfstudio.models.base import Model, ModelConfig
|
from nerfstudio.models.base_model import Model, ModelConfig
|
||||||
from nerfstudio.utils import colors, visualization
|
from nerfstudio.utils import colormaps, colors
|
||||||
from nerfstudio.utils.callbacks import (
|
|
||||||
TrainingCallback,
|
|
||||||
TrainingCallbackAttributes,
|
|
||||||
TrainingCallbackLocation,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -224,8 +224,8 @@ class NerfactoModel(Model):
|
|||||||
|
|
||||||
image = batch["image"].to(self.device)
|
image = batch["image"].to(self.device)
|
||||||
rgb = outputs["rgb"]
|
rgb = outputs["rgb"]
|
||||||
acc = visualization.apply_colormap(outputs["accumulation"])
|
acc = colormaps.apply_colormap(outputs["accumulation"])
|
||||||
depth = visualization.apply_depth_colormap(
|
depth = colormaps.apply_depth_colormap(
|
||||||
outputs["depth"],
|
outputs["depth"],
|
||||||
accumulation=outputs["accumulation"],
|
accumulation=outputs["accumulation"],
|
||||||
)
|
)
|
||||||
@@ -250,7 +250,7 @@ class NerfactoModel(Model):
|
|||||||
|
|
||||||
for i in range(self.config.num_proposal_network_iterations):
|
for i in range(self.config.num_proposal_network_iterations):
|
||||||
key = f"prop_depth_{i}"
|
key = f"prop_depth_{i}"
|
||||||
prop_depth_i = visualization.apply_depth_colormap(
|
prop_depth_i = colormaps.apply_depth_colormap(
|
||||||
outputs[key],
|
outputs[key],
|
||||||
accumulation=outputs["accumulation"],
|
accumulation=outputs["accumulation"],
|
||||||
)
|
)
|
||||||
|
|||||||
+10
-10
@@ -28,12 +28,12 @@ from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
|||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.configs.config_utils import to_immutable_dict
|
from nerfstudio.configs.config_utils import to_immutable_dict
|
||||||
from nerfstudio.field_components.encoding import NeRFEncoding
|
from nerfstudio.field_components.encodings import NeRFEncoding
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
|
||||||
from nerfstudio.fields.nerfw_field import VanillaNerfWField
|
from nerfstudio.fields.nerfw_field import VanillaNerfWField
|
||||||
from nerfstudio.model_components.loss import MSELoss
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
from nerfstudio.model_components.ray_sampler import PDFSampler, UniformSampler
|
from nerfstudio.model_components.losses import MSELoss
|
||||||
|
from nerfstudio.model_components.ray_samplers import PDFSampler, UniformSampler
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
@@ -41,8 +41,8 @@ from nerfstudio.model_components.renderers import (
|
|||||||
UncertaintyRenderer,
|
UncertaintyRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.model_components.scene_colliders import AABBBoxCollider
|
from nerfstudio.model_components.scene_colliders import AABBBoxCollider
|
||||||
from nerfstudio.models.base import Model, VanillaModelConfig
|
from nerfstudio.models.base_model import Model, VanillaModelConfig
|
||||||
from nerfstudio.utils import colors, misc, visualization
|
from nerfstudio.utils import colormaps, colors, misc
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -255,10 +255,10 @@ class NerfWModel(Model):
|
|||||||
depth_fine_static = outputs["depth_fine_static"]
|
depth_fine_static = outputs["depth_fine_static"]
|
||||||
uncertainty = outputs["uncertainty"]
|
uncertainty = outputs["uncertainty"]
|
||||||
|
|
||||||
depth_coarse = visualization.apply_depth_colormap(depth_coarse)
|
depth_coarse = colormaps.apply_depth_colormap(depth_coarse)
|
||||||
depth_fine = visualization.apply_depth_colormap(depth_fine)
|
depth_fine = colormaps.apply_depth_colormap(depth_fine)
|
||||||
depth_fine_static = visualization.apply_depth_colormap(depth_fine_static)
|
depth_fine_static = colormaps.apply_depth_colormap(depth_fine_static)
|
||||||
uncertainty = visualization.apply_depth_colormap(uncertainty)
|
uncertainty = colormaps.apply_depth_colormap(uncertainty)
|
||||||
|
|
||||||
row0 = torch.cat([image, uncertainty, torch.ones_like(rgb_fine)], dim=-2)
|
row0 = torch.cat([image, uncertainty, torch.ones_like(rgb_fine)], dim=-2)
|
||||||
row1 = torch.cat([rgb_fine, rgb_fine_static, rgb_coarse], dim=-2)
|
row1 = torch.cat([rgb_fine, rgb_fine_static, rgb_coarse], dim=-2)
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ from torch import nn
|
|||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.data.dataparsers.base_dataparser import Semantics
|
from nerfstudio.data.dataparsers.base_dataparser import Semantics
|
||||||
from nerfstudio.field_components.encoding import NeRFEncoding
|
from nerfstudio.field_components.encodings import NeRFEncoding
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
|
||||||
from nerfstudio.fields.semantic_nerf_field import SemanticNerfField
|
from nerfstudio.fields.semantic_nerf_field import SemanticNerfField
|
||||||
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
from nerfstudio.model_components.renderers import SemanticRenderer
|
from nerfstudio.model_components.renderers import SemanticRenderer
|
||||||
from nerfstudio.model_components.scene_colliders import AABBBoxCollider
|
from nerfstudio.model_components.scene_colliders import AABBBoxCollider
|
||||||
from nerfstudio.models.base import ModelConfig
|
from nerfstudio.models.base_model import ModelConfig
|
||||||
from nerfstudio.models.vanilla_nerf import NeRFModel
|
from nerfstudio.models.vanilla_nerf import NeRFModel
|
||||||
from nerfstudio.utils import misc
|
from nerfstudio.utils import misc
|
||||||
|
|
||||||
|
|||||||
@@ -30,24 +30,24 @@ from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
|||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.configs.config_utils import to_immutable_dict
|
from nerfstudio.configs.config_utils import to_immutable_dict
|
||||||
|
from nerfstudio.engine.callbacks import (
|
||||||
|
TrainingCallback,
|
||||||
|
TrainingCallbackAttributes,
|
||||||
|
TrainingCallbackLocation,
|
||||||
|
)
|
||||||
from nerfstudio.engine.optimizers import Optimizers
|
from nerfstudio.engine.optimizers import Optimizers
|
||||||
from nerfstudio.field_components.encoding import TensorVMEncoding
|
from nerfstudio.field_components.encodings import TensorVMEncoding
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
from nerfstudio.model_components.loss import L1Loss, MSELoss
|
from nerfstudio.model_components.losses import L1Loss, MSELoss
|
||||||
from nerfstudio.model_components.ray_sampler import PDFSampler, UniformSampler
|
from nerfstudio.model_components.ray_samplers import PDFSampler, UniformSampler
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.models.base import Model, VanillaModelConfig
|
from nerfstudio.models.base_model import Model, VanillaModelConfig
|
||||||
from nerfstudio.utils import colors, misc, visualization
|
from nerfstudio.utils import colormaps, colors, misc
|
||||||
from nerfstudio.utils.callbacks import (
|
|
||||||
TrainingCallback,
|
|
||||||
TrainingCallbackAttributes,
|
|
||||||
TrainingCallbackLocation,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -215,8 +215,8 @@ class TensoRFModel(Model):
|
|||||||
) -> Tuple[Dict[str, float], Dict[str, torch.Tensor]]:
|
) -> Tuple[Dict[str, float], Dict[str, torch.Tensor]]:
|
||||||
image = batch["image"].to(outputs["rgb"].device)
|
image = batch["image"].to(outputs["rgb"].device)
|
||||||
rgb = outputs["rgb"]
|
rgb = outputs["rgb"]
|
||||||
acc = visualization.apply_colormap(outputs["accumulation"])
|
acc = colormaps.apply_colormap(outputs["accumulation"])
|
||||||
depth = visualization.apply_depth_colormap(
|
depth = colormaps.apply_depth_colormap(
|
||||||
outputs["depth"],
|
outputs["depth"],
|
||||||
accumulation=outputs["accumulation"],
|
accumulation=outputs["accumulation"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
|
|||||||
@@ -27,18 +27,18 @@ from torchmetrics.functional import structural_similarity_index_measure
|
|||||||
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.field_components.encoding import NeRFEncoding
|
from nerfstudio.field_components.encodings import NeRFEncoding
|
||||||
from nerfstudio.field_components.field_heads import FieldHeadNames
|
from nerfstudio.field_components.field_heads import FieldHeadNames
|
||||||
from nerfstudio.fields.nerf_field import NeRFField
|
from nerfstudio.fields.vanilla_nerf_field import NeRFField
|
||||||
from nerfstudio.model_components.loss import MSELoss
|
from nerfstudio.model_components.losses import MSELoss
|
||||||
from nerfstudio.model_components.ray_sampler import PDFSampler, UniformSampler
|
from nerfstudio.model_components.ray_samplers import PDFSampler, UniformSampler
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.models.base import Model, ModelConfig
|
from nerfstudio.models.base_model import Model, ModelConfig
|
||||||
from nerfstudio.utils import colors, misc, visualization
|
from nerfstudio.utils import colormaps, colors, misc
|
||||||
|
|
||||||
|
|
||||||
class NeRFModel(Model):
|
class NeRFModel(Model):
|
||||||
@@ -159,15 +159,15 @@ class NeRFModel(Model):
|
|||||||
image = batch["image"].to(outputs["rgb_coarse"].device)
|
image = batch["image"].to(outputs["rgb_coarse"].device)
|
||||||
rgb_coarse = outputs["rgb_coarse"]
|
rgb_coarse = outputs["rgb_coarse"]
|
||||||
rgb_fine = outputs["rgb_fine"]
|
rgb_fine = outputs["rgb_fine"]
|
||||||
acc_coarse = visualization.apply_colormap(outputs["accumulation_coarse"])
|
acc_coarse = colormaps.apply_colormap(outputs["accumulation_coarse"])
|
||||||
acc_fine = visualization.apply_colormap(outputs["accumulation_fine"])
|
acc_fine = colormaps.apply_colormap(outputs["accumulation_fine"])
|
||||||
depth_coarse = visualization.apply_depth_colormap(
|
depth_coarse = colormaps.apply_depth_colormap(
|
||||||
outputs["depth_coarse"],
|
outputs["depth_coarse"],
|
||||||
accumulation=outputs["accumulation_coarse"],
|
accumulation=outputs["accumulation_coarse"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
far_plane=self.config.collider_params["far_plane"],
|
far_plane=self.config.collider_params["far_plane"],
|
||||||
)
|
)
|
||||||
depth_fine = visualization.apply_depth_colormap(
|
depth_fine = colormaps.apply_depth_colormap(
|
||||||
outputs["depth_fine"],
|
outputs["depth_fine"],
|
||||||
accumulation=outputs["accumulation_fine"],
|
accumulation=outputs["accumulation_fine"],
|
||||||
near_plane=self.config.collider_params["near_plane"],
|
near_plane=self.config.collider_params["near_plane"],
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ from nerfstudio.data.datamanagers import (
|
|||||||
VanillaDataManager,
|
VanillaDataManager,
|
||||||
VanillaDataManagerConfig,
|
VanillaDataManagerConfig,
|
||||||
)
|
)
|
||||||
from nerfstudio.models.base import Model, ModelConfig
|
from nerfstudio.engine.callbacks import TrainingCallback, TrainingCallbackAttributes
|
||||||
|
from nerfstudio.models.base_model import Model, ModelConfig
|
||||||
from nerfstudio.utils import profiler
|
from nerfstudio.utils import profiler
|
||||||
from nerfstudio.utils.callbacks import TrainingCallback, TrainingCallbackAttributes
|
|
||||||
from nerfstudio.utils.misc import get_masked_dict
|
from nerfstudio.utils.misc import get_masked_dict
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ from typing import Type
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
from nerfstudio.data.datamanagers import VanillaDataManager
|
from nerfstudio.data.datamanagers import VanillaDataManager
|
||||||
from nerfstudio.pipelines.base import VanillaPipeline, VanillaPipelineConfig
|
from nerfstudio.pipelines.base_pipeline import VanillaPipeline, VanillaPipelineConfig
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
# Copyright 2022 The Plenoptix 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.
|
|
||||||
|
|
||||||
"""
|
|
||||||
Pipeline for pixel nerf.
|
|
||||||
"""
|
|
||||||
File renamed without changes.
+1
-25
@@ -15,10 +15,9 @@
|
|||||||
"""
|
"""
|
||||||
Input/output utils.
|
Input/output utils.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import pickle
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
|
|
||||||
def load_from_json(filename: Path):
|
def load_from_json(filename: Path):
|
||||||
@@ -42,26 +41,3 @@ def write_to_json(filename: Path, content: dict):
|
|||||||
assert filename.suffix == ".json"
|
assert filename.suffix == ".json"
|
||||||
with open(filename, "w", encoding="UTF-8") as file:
|
with open(filename, "w", encoding="UTF-8") as file:
|
||||||
json.dump(content, file)
|
json.dump(content, file)
|
||||||
|
|
||||||
|
|
||||||
def load_from_pkl(filename: Path):
|
|
||||||
"""Load from a pickle file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
filename: The filename to load from.
|
|
||||||
"""
|
|
||||||
assert filename.suffix == ".pkl"
|
|
||||||
with open(filename, "rb") as f:
|
|
||||||
return pickle.load(f)
|
|
||||||
|
|
||||||
|
|
||||||
def write_to_pkl(filename: Path, content: Any):
|
|
||||||
"""Write to a pickle file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
filename (str): The filename to write to.
|
|
||||||
content (Any): The data to write.
|
|
||||||
"""
|
|
||||||
assert filename.suffix == ".pkl"
|
|
||||||
with open(filename, "wb") as f:
|
|
||||||
pickle.dump(content, f)
|
|
||||||
@@ -16,9 +16,6 @@
|
|||||||
Miscellaneous helper code.
|
Miscellaneous helper code.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
from math import floor, log
|
|
||||||
from typing import Any, Callable, Dict, List, Optional, Union
|
from typing import Any, Callable, Dict, List, Optional, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
@@ -59,11 +56,6 @@ def get_dict_to_cpu(stuff: Any):
|
|||||||
return stuff
|
return stuff
|
||||||
|
|
||||||
|
|
||||||
def is_not_none(var: Any) -> bool:
|
|
||||||
"""Return True if the variable var is None."""
|
|
||||||
return not isinstance(var, type(None))
|
|
||||||
|
|
||||||
|
|
||||||
def get_masked_dict(d, mask):
|
def get_masked_dict(d, mask):
|
||||||
"""Return a masked dictionary.
|
"""Return a masked dictionary.
|
||||||
TODO(ethan): add more asserts/checks so this doesn't have unpredictable behavior.
|
TODO(ethan): add more asserts/checks so this doesn't have unpredictable behavior.
|
||||||
@@ -78,19 +70,6 @@ def get_masked_dict(d, mask):
|
|||||||
return masked_dict
|
return masked_dict
|
||||||
|
|
||||||
|
|
||||||
def get_hash_str_from_dict(dictionary: Dict[str, Any]) -> str:
|
|
||||||
"""MD5 hash of a dictionary. Based on
|
|
||||||
https://www.doc.ic.ac.uk/~nuric/coding/how-to-hash-a-dictionary-in-python.html
|
|
||||||
|
|
||||||
Args:
|
|
||||||
dictionary: dict to process
|
|
||||||
"""
|
|
||||||
dhash = hashlib.md5()
|
|
||||||
encoded = json.dumps(dictionary, sort_keys=True).encode()
|
|
||||||
dhash.update(encoded)
|
|
||||||
return dhash.hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
class IterableWrapper: # pylint: disable=too-few-public-methods
|
class IterableWrapper: # pylint: disable=too-few-public-methods
|
||||||
"""A helper that will allow an instance of a class to return multiple kinds of iterables bound
|
"""A helper that will allow an instance of a class to return multiple kinds of iterables bound
|
||||||
to different functions of that class.
|
to different functions of that class.
|
||||||
@@ -133,18 +112,6 @@ class IterableWrapper: # pylint: disable=too-few-public-methods
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
def human_format(num):
|
|
||||||
"""Format a number in a more human readable way
|
|
||||||
|
|
||||||
Args:
|
|
||||||
num: number to format
|
|
||||||
"""
|
|
||||||
units = ["", "K", "M", "B", "T", "P"]
|
|
||||||
k = 1000.0
|
|
||||||
magnitude = int(floor(log(num, k)))
|
|
||||||
return f"{(num / k**magnitude):.2f} {units[magnitude]}"
|
|
||||||
|
|
||||||
|
|
||||||
def scale_dict(dictionary: Dict[Any, Any], coefficients: Dict[str, float]) -> Dict[Any, Any]:
|
def scale_dict(dictionary: Dict[Any, Any], coefficients: Dict[str, float]) -> Dict[Any, Any]:
|
||||||
"""Scale a dictionary in-place given a coefficients dictionary.
|
"""Scale a dictionary in-place given a coefficients dictionary.
|
||||||
|
|
||||||
@@ -168,7 +135,7 @@ def step_check(step, step_size, run_at_zero=False) -> bool:
|
|||||||
return (run_at_zero or step != 0) and step % step_size == 0
|
return (run_at_zero or step != 0) and step % step_size == 0
|
||||||
|
|
||||||
|
|
||||||
def _update_avg(prev_avg: float, new_val: float, step: int) -> float:
|
def update_avg(prev_avg: float, new_val: float, step: int) -> float:
|
||||||
"""helper to calculate the running average
|
"""helper to calculate the running average
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
File renamed without changes.
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
"""A collection of common strings and print statements used throughout the codebase."""
|
"""A collection of common strings and print statements used throughout the codebase."""
|
||||||
|
|
||||||
|
from math import floor, log
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
console = Console(width=120)
|
console = Console(width=120)
|
||||||
@@ -29,3 +31,15 @@ def print_tcnn_speed_warning(method_name: str):
|
|||||||
)
|
)
|
||||||
console.print("[yellow]pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch")
|
console.print("[yellow]pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch")
|
||||||
console.line()
|
console.line()
|
||||||
|
|
||||||
|
|
||||||
|
def human_format(num):
|
||||||
|
"""Format a number in a more human readable way
|
||||||
|
|
||||||
|
Args:
|
||||||
|
num: number to format
|
||||||
|
"""
|
||||||
|
units = ["", "K", "M", "B", "T", "P"]
|
||||||
|
k = 1000.0
|
||||||
|
magnitude = int(floor(log(num, k)))
|
||||||
|
return f"{(num / k**magnitude):.2f} {units[magnitude]}"
|
||||||
@@ -32,7 +32,7 @@ from torchtyping import TensorType
|
|||||||
|
|
||||||
from nerfstudio.configs import base_config as cfg
|
from nerfstudio.configs import base_config as cfg
|
||||||
from nerfstudio.utils.decorators import check_main_thread, decorate_all
|
from nerfstudio.utils.decorators import check_main_thread, decorate_all
|
||||||
from nerfstudio.utils.misc import human_format
|
from nerfstudio.utils.printing import human_format
|
||||||
|
|
||||||
CONSOLE = console.Console()
|
CONSOLE = console.Console()
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default function LandingModel(props: LandingModalProps) {
|
|||||||
const handleOpen = () => setOpen(true);
|
const handleOpen = () => setOpen(true);
|
||||||
const handleClose = () => setOpen(false);
|
const handleClose = () => setOpen(false);
|
||||||
|
|
||||||
const text_intro = `At the top right is the Status Panel where you can connect to a WebSocket and see the train/eval status of your NeRF model. The WebSocket Port takes the form <domain-or-ip_address>:<port>.`;
|
const text_intro = `To use our viewer, you need to connect to the WebSocket server where your training job is running.`;
|
||||||
|
|
||||||
const websocket_port = useSelector(
|
const websocket_port = useSelector(
|
||||||
(state) => state.websocketState.websocket_port,
|
(state) => state.websocketState.websocket_port,
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ def run_viewer_bridge_server_as_subprocess(
|
|||||||
"You likely have to modify --viewer.zmq-port and/or --viewer.websocket-port in the "
|
"You likely have to modify --viewer.zmq-port and/or --viewer.websocket-port in the "
|
||||||
"config to avoid conflicting ports.\n"
|
"config to avoid conflicting ports.\n"
|
||||||
)
|
)
|
||||||
string += "Try modifying --viewer.zmq-port 6000 --viewer.websocket-port 7007\n"
|
string += "Try modifying --viewer.websocket-port 7007\n"
|
||||||
CONSOLE.print(f"[bold red]{string}")
|
CONSOLE.print(f"[bold red]{string}")
|
||||||
cleanup(process)
|
cleanup(process)
|
||||||
# This exists the entire program. sys.exit() will only kill the thread that this runs in.
|
# This exists the entire program. sys.exit() will only kill the thread that this runs in.
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ from nerfstudio.cameras.cameras import Cameras
|
|||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.configs import base_config as cfg
|
from nerfstudio.configs import base_config as cfg
|
||||||
from nerfstudio.data.utils.datasets import InputDataset
|
from nerfstudio.data.utils.datasets import InputDataset
|
||||||
from nerfstudio.models.base import Model
|
from nerfstudio.models.base_model import Model
|
||||||
from nerfstudio.utils import profiler, visualization, writer
|
from nerfstudio.utils import colormaps, profiler, writer
|
||||||
from nerfstudio.utils.decorators import check_main_thread, decorate_all
|
from nerfstudio.utils.decorators import check_main_thread, decorate_all
|
||||||
from nerfstudio.utils.io import load_from_json, write_to_json
|
from nerfstudio.utils.io import load_from_json, write_to_json
|
||||||
from nerfstudio.utils.misc import get_dict_to_torch
|
from nerfstudio.utils.misc import get_dict_to_torch
|
||||||
@@ -407,15 +407,13 @@ class ViewerState:
|
|||||||
if OutputTypes.ACCUMULATION in self.output_list
|
if OutputTypes.ACCUMULATION in self.output_list
|
||||||
else OutputTypes.ACCUMULATION_FINE
|
else OutputTypes.ACCUMULATION_FINE
|
||||||
)
|
)
|
||||||
return visualization.apply_depth_colormap(
|
return colormaps.apply_depth_colormap(outputs[reformatted_output], accumulation=outputs[accumulation_str])
|
||||||
outputs[reformatted_output], accumulation=outputs[accumulation_str]
|
|
||||||
)
|
|
||||||
|
|
||||||
# rendering accumulation outputs
|
# rendering accumulation outputs
|
||||||
if self.prev_colormap_type == ColormapTypes.TURBO or (
|
if self.prev_colormap_type == ColormapTypes.TURBO or (
|
||||||
self.prev_colormap_type == ColormapTypes.DEFAULT and outputs[reformatted_output].dtype == torch.float
|
self.prev_colormap_type == ColormapTypes.DEFAULT and outputs[reformatted_output].dtype == torch.float
|
||||||
):
|
):
|
||||||
return visualization.apply_colormap(outputs[reformatted_output])
|
return colormaps.apply_colormap(outputs[reformatted_output])
|
||||||
|
|
||||||
# rendering semantic outputs
|
# rendering semantic outputs
|
||||||
if self.prev_colormap_type == ColormapTypes.SEMANTIC or (
|
if self.prev_colormap_type == ColormapTypes.SEMANTIC or (
|
||||||
@@ -430,7 +428,7 @@ class ViewerState:
|
|||||||
if self.prev_colormap_type == ColormapTypes.BOOLEAN or (
|
if self.prev_colormap_type == ColormapTypes.BOOLEAN or (
|
||||||
self.prev_colormap_type == ColormapTypes.DEFAULT and outputs[reformatted_output].dtype == torch.bool
|
self.prev_colormap_type == ColormapTypes.DEFAULT and outputs[reformatted_output].dtype == torch.bool
|
||||||
):
|
):
|
||||||
return visualization.apply_boolean_colormap(outputs[reformatted_output])
|
return colormaps.apply_boolean_colormap(outputs[reformatted_output])
|
||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ from typing_extensions import assert_never
|
|||||||
from nerfstudio.cameras.camera_paths import get_path_from_json, get_spiral_path
|
from nerfstudio.cameras.camera_paths import get_path_from_json, get_spiral_path
|
||||||
from nerfstudio.cameras.cameras import Cameras
|
from nerfstudio.cameras.cameras import Cameras
|
||||||
from nerfstudio.configs import base_config as cfg
|
from nerfstudio.configs import base_config as cfg
|
||||||
from nerfstudio.pipelines.base import Pipeline
|
from nerfstudio.pipelines.base_pipeline import Pipeline
|
||||||
from nerfstudio.utils.rich_utils import ItersPerSecColumn
|
from nerfstudio.utils.rich_utils import ItersPerSecColumn
|
||||||
|
|
||||||
console = Console(width=120)
|
console = Console(width=120)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Encoding Tests
|
|||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from nerfstudio.field_components import encoding
|
from nerfstudio.field_components import encodings
|
||||||
|
|
||||||
|
|
||||||
def test_scaling_and_offset():
|
def test_scaling_and_offset():
|
||||||
@@ -14,7 +14,7 @@ def test_scaling_and_offset():
|
|||||||
|
|
||||||
scaling = 2.0
|
scaling = 2.0
|
||||||
offset = 4.5
|
offset = 4.5
|
||||||
encoder = encoding.ScalingAndOffset(in_dim=in_dim, scaling=scaling, offset=offset)
|
encoder = encodings.ScalingAndOffset(in_dim=in_dim, scaling=scaling, offset=offset)
|
||||||
|
|
||||||
assert encoder.get_out_dim() == in_dim
|
assert encoder.get_out_dim() == in_dim
|
||||||
encoded = encoder(in_tensor)
|
encoded = encoder(in_tensor)
|
||||||
@@ -22,7 +22,7 @@ def test_scaling_and_offset():
|
|||||||
assert in_tensor * 6.5 == pytest.approx(encoded)
|
assert in_tensor * 6.5 == pytest.approx(encoded)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
encoding.ScalingAndOffset(in_dim=-1)
|
encodings.ScalingAndOffset(in_dim=-1)
|
||||||
|
|
||||||
|
|
||||||
def test_nerf_encoder():
|
def test_nerf_encoder():
|
||||||
@@ -34,7 +34,7 @@ def test_nerf_encoder():
|
|||||||
num_frequencies = 3
|
num_frequencies = 3
|
||||||
min_freq_exp = 0
|
min_freq_exp = 0
|
||||||
max_freq_exp = 3
|
max_freq_exp = 3
|
||||||
encoder = encoding.NeRFEncoding(
|
encoder = encodings.NeRFEncoding(
|
||||||
in_dim=in_dim, num_frequencies=num_frequencies, min_freq_exp=min_freq_exp, max_freq_exp=max_freq_exp
|
in_dim=in_dim, num_frequencies=num_frequencies, min_freq_exp=min_freq_exp, max_freq_exp=max_freq_exp
|
||||||
)
|
)
|
||||||
assert encoder.get_out_dim() == out_dim
|
assert encoder.get_out_dim() == out_dim
|
||||||
@@ -62,7 +62,7 @@ def test_rff_encoder():
|
|||||||
|
|
||||||
num_frequencies = 12
|
num_frequencies = 12
|
||||||
scale = 5
|
scale = 5
|
||||||
encoder = encoding.RFFEncoding(in_dim=in_dim, num_frequencies=num_frequencies, scale=scale)
|
encoder = encodings.RFFEncoding(in_dim=in_dim, num_frequencies=num_frequencies, scale=scale)
|
||||||
assert encoder.get_out_dim() == out_dim
|
assert encoder.get_out_dim() == out_dim
|
||||||
|
|
||||||
in_tensor = torch.ones((2, 3, in_dim))
|
in_tensor = torch.ones((2, 3, in_dim))
|
||||||
@@ -83,7 +83,7 @@ def test_tensor_vm_encoder():
|
|||||||
in_dim = 3
|
in_dim = 3
|
||||||
out_dim = 3 * num_components
|
out_dim = 3 * num_components
|
||||||
|
|
||||||
encoder = encoding.TensorVMEncoding(num_components=num_components, resolution=resolution)
|
encoder = encodings.TensorVMEncoding(num_components=num_components, resolution=resolution)
|
||||||
assert encoder.get_out_dim() == out_dim
|
assert encoder.get_out_dim() == out_dim
|
||||||
|
|
||||||
in_tensor = torch.ones((3, in_dim))
|
in_tensor = torch.ones((3, in_dim))
|
||||||
@@ -107,7 +107,7 @@ def test_tensor_cp_encoder():
|
|||||||
in_dim = 3
|
in_dim = 3
|
||||||
out_dim = num_components
|
out_dim = num_components
|
||||||
|
|
||||||
encoder = encoding.TensorCPEncoding(num_components=num_components, resolution=resolution)
|
encoder = encodings.TensorCPEncoding(num_components=num_components, resolution=resolution)
|
||||||
assert encoder.get_out_dim() == out_dim
|
assert encoder.get_out_dim() == out_dim
|
||||||
|
|
||||||
in_tensor = torch.ones((3, in_dim))
|
in_tensor = torch.ones((3, in_dim))
|
||||||
@@ -128,9 +128,9 @@ def test_tensor_sh_encoder():
|
|||||||
out_dim = levels**2
|
out_dim = levels**2
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
encoder = encoding.SHEncoding(levels=5)
|
encoder = encodings.SHEncoding(levels=5)
|
||||||
|
|
||||||
encoder = encoding.SHEncoding(levels=levels)
|
encoder = encodings.SHEncoding(levels=levels)
|
||||||
assert encoder.get_out_dim() == out_dim
|
assert encoder.get_out_dim() == out_dim
|
||||||
|
|
||||||
in_tensor = torch.zeros((10, 3))
|
in_tensor = torch.zeros((10, 3))
|
||||||
@@ -146,7 +146,7 @@ def test_tensor_hash_encoder():
|
|||||||
features_per_level = 4
|
features_per_level = 4
|
||||||
out_dim = num_levels * features_per_level
|
out_dim = num_levels * features_per_level
|
||||||
|
|
||||||
encoder = encoding.HashEncoding(
|
encoder = encodings.HashEncoding(
|
||||||
num_levels=num_levels,
|
num_levels=num_levels,
|
||||||
features_per_level=features_per_level,
|
features_per_level=features_per_level,
|
||||||
log2_hashmap_size=5,
|
log2_hashmap_size=5,
|
||||||
@@ -159,7 +159,7 @@ def test_tensor_hash_encoder():
|
|||||||
encoded = encoder(in_tensor)
|
encoded = encoder(in_tensor)
|
||||||
assert encoded.shape == (10, out_dim)
|
assert encoded.shape == (10, out_dim)
|
||||||
|
|
||||||
encoder = encoding.HashEncoding(
|
encoder = encodings.HashEncoding(
|
||||||
num_levels=num_levels,
|
num_levels=num_levels,
|
||||||
features_per_level=features_per_level,
|
features_per_level=features_per_level,
|
||||||
log2_hashmap_size=5,
|
log2_hashmap_size=5,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Test samplers
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
from nerfstudio.cameras.rays import RayBundle
|
from nerfstudio.cameras.rays import RayBundle
|
||||||
from nerfstudio.model_components.ray_sampler import (
|
from nerfstudio.model_components.ray_samplers import (
|
||||||
LinearDisparitySampler,
|
LinearDisparitySampler,
|
||||||
LogSampler,
|
LogSampler,
|
||||||
PDFSampler,
|
PDFSampler,
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
"""
|
"""
|
||||||
Test visualizations
|
Test colormaps
|
||||||
"""
|
"""
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from nerfstudio.utils import visualization
|
from nerfstudio.utils import colormaps
|
||||||
|
|
||||||
|
|
||||||
def test_apply_colormap():
|
def test_apply_colormap():
|
||||||
"""Test adding a colormap to data"""
|
"""Test adding a colormap to data"""
|
||||||
data = torch.rand((10, 20, 1))
|
data = torch.rand((10, 20, 1))
|
||||||
colored_data = visualization.apply_colormap(data)
|
colored_data = colormaps.apply_colormap(data)
|
||||||
|
|
||||||
assert colored_data.shape == (10, 20, 3)
|
assert colored_data.shape == (10, 20, 3)
|
||||||
assert torch.min(colored_data) >= 0
|
assert torch.min(colored_data) >= 0
|
||||||
@@ -21,7 +21,7 @@ def test_apply_depth_colormap():
|
|||||||
data = torch.rand((10, 20, 1))
|
data = torch.rand((10, 20, 1))
|
||||||
accum = torch.rand((10, 20, 1))
|
accum = torch.rand((10, 20, 1))
|
||||||
accum = accum / torch.max(accum)
|
accum = accum / torch.max(accum)
|
||||||
colored_data = visualization.apply_depth_colormap(depth=data, accumulation=accum)
|
colored_data = colormaps.apply_depth_colormap(depth=data, accumulation=accum)
|
||||||
|
|
||||||
assert colored_data.shape == (10, 20, 3)
|
assert colored_data.shape == (10, 20, 3)
|
||||||
assert torch.min(colored_data) >= 0
|
assert torch.min(colored_data) >= 0
|
||||||
@@ -32,7 +32,7 @@ def test_apply_boolean_colormap():
|
|||||||
"""Test adding a colormap to boolean data"""
|
"""Test adding a colormap to boolean data"""
|
||||||
data = torch.rand((10, 20, 1))
|
data = torch.rand((10, 20, 1))
|
||||||
data = data > 0.5
|
data = data > 0.5
|
||||||
colored_data = visualization.apply_boolean_colormap(data)
|
colored_data = colormaps.apply_boolean_colormap(data)
|
||||||
|
|
||||||
assert colored_data.shape == (10, 20, 3)
|
assert colored_data.shape == (10, 20, 3)
|
||||||
assert torch.min(colored_data) >= 0
|
assert torch.min(colored_data) >= 0
|
||||||
|
|||||||
Reference in new issue
Block a user