mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-01 21:39:06 +08:00
Normals in dreamfusion
This commit is contained in:
1 parent
b57781ab0c
commit
44d6431c43
2 files changed
+29
-24
No files matched your search
@@ -85,7 +85,6 @@ class DreamFusionField(Field):
|
|||||||
num_layers_color: int = 3,
|
num_layers_color: int = 3,
|
||||||
hidden_dim_color: int = 64,
|
hidden_dim_color: int = 64,
|
||||||
hidden_dim_transient: int = 64,
|
hidden_dim_transient: int = 64,
|
||||||
use_pred_normals: bool = False,
|
|
||||||
spatial_distortion: Optional[SpatialDistortion] = None,
|
spatial_distortion: Optional[SpatialDistortion] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -94,7 +93,6 @@ class DreamFusionField(Field):
|
|||||||
self.geo_feat_dim = geo_feat_dim
|
self.geo_feat_dim = geo_feat_dim
|
||||||
|
|
||||||
self.spatial_distortion = spatial_distortion
|
self.spatial_distortion = spatial_distortion
|
||||||
self.use_pred_normals = use_pred_normals
|
|
||||||
|
|
||||||
num_levels = 16
|
num_levels = 16
|
||||||
max_res = 1024
|
max_res = 1024
|
||||||
@@ -129,19 +127,18 @@ class DreamFusionField(Field):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# predicted normals
|
# predicted normals
|
||||||
if self.use_pred_normals:
|
self.mlp_pred_normals = tcnn.Network(
|
||||||
self.mlp_pred_normals = tcnn.Network(
|
n_input_dims=self.geo_feat_dim + self.position_encoding.n_output_dims,
|
||||||
n_input_dims=self.geo_feat_dim + self.position_encoding.n_output_dims,
|
n_output_dims=hidden_dim_transient,
|
||||||
n_output_dims=hidden_dim_transient,
|
network_config={
|
||||||
network_config={
|
"otype": "FullyFusedMLP",
|
||||||
"otype": "FullyFusedMLP",
|
"activation": "ReLU",
|
||||||
"activation": "ReLU",
|
"output_activation": "None",
|
||||||
"output_activation": "None",
|
"n_neurons": 64,
|
||||||
"n_neurons": 64,
|
"n_hidden_layers": 2,
|
||||||
"n_hidden_layers": 2,
|
},
|
||||||
},
|
)
|
||||||
)
|
self.field_head_pred_normals = PredNormalsFieldHead(in_dim=self.mlp_pred_normals.n_output_dims)
|
||||||
self.field_head_pred_normals = PredNormalsFieldHead(in_dim=self.mlp_pred_normals.n_output_dims)
|
|
||||||
|
|
||||||
self.mlp_head = tcnn.Network(
|
self.mlp_head = tcnn.Network(
|
||||||
n_input_dims=self.geo_feat_dim,
|
n_input_dims=self.geo_feat_dim,
|
||||||
@@ -182,19 +179,17 @@ class DreamFusionField(Field):
|
|||||||
outputs = {}
|
outputs = {}
|
||||||
|
|
||||||
directions = get_normalized_directions(ray_samples.frustums.directions)
|
directions = get_normalized_directions(ray_samples.frustums.directions)
|
||||||
directions_flat = directions.view(-1, 3)
|
|
||||||
|
|
||||||
outputs_shape = ray_samples.frustums.directions.shape[:-1]
|
outputs_shape = ray_samples.frustums.directions.shape[:-1]
|
||||||
|
|
||||||
# predicted normals
|
# predicted normals
|
||||||
if self.use_pred_normals:
|
positions = ray_samples.frustums.get_positions()
|
||||||
positions = ray_samples.frustums.get_positions()
|
|
||||||
|
|
||||||
positions_flat = self.position_encoding(positions.view(-1, 3))
|
positions_flat = self.position_encoding(positions.view(-1, 3))
|
||||||
pred_normals_inp = torch.cat([positions_flat, density_embedding.view(-1, self.geo_feat_dim)], dim=-1)
|
pred_normals_inp = torch.cat([positions_flat, density_embedding.view(-1, self.geo_feat_dim)], dim=-1)
|
||||||
|
|
||||||
x = self.mlp_pred_normals(pred_normals_inp).view(*outputs_shape, -1).to(directions)
|
x = self.mlp_pred_normals(pred_normals_inp).view(*outputs_shape, -1).to(directions)
|
||||||
outputs[FieldHeadNames.PRED_NORMALS] = self.field_head_pred_normals(x)
|
outputs[FieldHeadNames.PRED_NORMALS] = self.field_head_pred_normals(x)
|
||||||
|
|
||||||
h = density_embedding.view(-1, self.geo_feat_dim)
|
h = density_embedding.view(-1, self.geo_feat_dim)
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ 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,
|
||||||
|
NormalsRenderer,
|
||||||
RGBRenderer,
|
RGBRenderer,
|
||||||
)
|
)
|
||||||
from nerfstudio.model_components.scene_colliders import AABBBoxCollider
|
from nerfstudio.model_components.scene_colliders import AABBBoxCollider
|
||||||
@@ -87,6 +88,7 @@ class DreamFusionModel(Model):
|
|||||||
self.renderer_rgb = RGBRenderer(background_color=colors.WHITE)
|
self.renderer_rgb = RGBRenderer(background_color=colors.WHITE)
|
||||||
self.renderer_accumulation = AccumulationRenderer()
|
self.renderer_accumulation = AccumulationRenderer()
|
||||||
self.renderer_depth = DepthRenderer()
|
self.renderer_depth = DepthRenderer()
|
||||||
|
self.renderer_normals = NormalsRenderer()
|
||||||
|
|
||||||
# losses
|
# losses
|
||||||
self.rgb_loss = MSELoss()
|
self.rgb_loss = MSELoss()
|
||||||
@@ -108,14 +110,22 @@ class DreamFusionModel(Model):
|
|||||||
def get_outputs(self, ray_bundle: RayBundle):
|
def get_outputs(self, ray_bundle: RayBundle):
|
||||||
# uniform sampling
|
# uniform sampling
|
||||||
ray_samples_uniform = self.sampler_uniform(ray_bundle)
|
ray_samples_uniform = self.sampler_uniform(ray_bundle)
|
||||||
field_outputs = self.field(ray_samples_uniform)
|
field_outputs = self.field(ray_samples_uniform, compute_normals=True)
|
||||||
weights = ray_samples_uniform.get_weights(field_outputs[FieldHeadNames.DENSITY])
|
weights = ray_samples_uniform.get_weights(field_outputs[FieldHeadNames.DENSITY])
|
||||||
|
|
||||||
accumulation = self.renderer_accumulation(weights)
|
accumulation = self.renderer_accumulation(weights)
|
||||||
depth = self.renderer_depth(weights, ray_samples_uniform)
|
depth = self.renderer_depth(weights, ray_samples_uniform)
|
||||||
rgb = self.renderer_rgb(rgb=field_outputs[FieldHeadNames.RGB], weights=weights)
|
rgb = self.renderer_rgb(rgb=field_outputs[FieldHeadNames.RGB], weights=weights)
|
||||||
|
normals = self.renderer_normals(normals=field_outputs[FieldHeadNames.NORMALS], weights=weights)
|
||||||
|
pred_normals = self.renderer_normals(field_outputs[FieldHeadNames.PRED_NORMALS], weights=weights)
|
||||||
|
|
||||||
outputs = {"rgb": rgb, "accumulation": accumulation, "depth": depth}
|
outputs = {
|
||||||
|
"rgb": rgb,
|
||||||
|
"accumulation": accumulation,
|
||||||
|
"depth": depth,
|
||||||
|
"normals": normals,
|
||||||
|
"pred_normals": pred_normals,
|
||||||
|
}
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def get_loss_dict(self, outputs, batch, metrics_dict=None) -> Dict[str, torch.Tensor]:
|
def get_loss_dict(self, outputs, batch, metrics_dict=None) -> Dict[str, torch.Tensor]:
|
||||||
|
|||||||
Reference in new issue
Block a user