mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
Update configs
This commit is contained in:
1 parent
c5bf04d595
commit
5b4d4544e3
4 files changed
+66
-33
No files matched your search
@@ -350,14 +350,23 @@ method_configs["dreamfusion"] = DreamfusionTrainerConfig(
|
|||||||
train_num_rays_per_batch=4096,
|
train_num_rays_per_batch=4096,
|
||||||
eval_num_rays_per_batch=4096,
|
eval_num_rays_per_batch=4096,
|
||||||
),
|
),
|
||||||
model=DreamFusionModelConfig(eval_num_rays_per_chunk=1 << 15, distortion_loss_mult=10),
|
model=DreamFusionModelConfig(
|
||||||
|
eval_num_rays_per_chunk=1 << 15,
|
||||||
|
distortion_loss_mult=10,
|
||||||
|
sphere_collider=True,
|
||||||
|
initialize_density=False,
|
||||||
|
interlevel_loss_mult=1.0,
|
||||||
|
proposal_warmup=500,
|
||||||
|
proposal_update_every=5,
|
||||||
|
proposal_weights_anneal_max_num_iters=100,
|
||||||
|
),
|
||||||
alphas_loss_mult=1.0,
|
alphas_loss_mult=1.0,
|
||||||
opacity_loss_mult=1.0,
|
opacity_loss_mult=1.0,
|
||||||
guidance_scale=100,
|
guidance_scale=100,
|
||||||
),
|
),
|
||||||
optimizers={
|
optimizers={
|
||||||
"proposal_networks": {
|
"proposal_networks": {
|
||||||
"optimizer": AdamOptimizerConfig(lr=1e-2, eps=1e-15),
|
"optimizer": AdamOptimizerConfig(lr=5e-2, eps=1e-15),
|
||||||
"scheduler": None,
|
"scheduler": None,
|
||||||
},
|
},
|
||||||
"fields": {
|
"fields": {
|
||||||
|
|||||||
@@ -60,23 +60,28 @@ class TrivialDataset(InputDataset):
|
|||||||
|
|
||||||
|
|
||||||
def random_train_pose(
|
def random_train_pose(
|
||||||
size,
|
size: int,
|
||||||
resolution,
|
resolution: int,
|
||||||
device,
|
device: Union[torch.device, str],
|
||||||
radius_mean=1.0,
|
radius_mean: float = 1.0,
|
||||||
radius_std=0.1,
|
radius_std: float = 0.1,
|
||||||
central_rotation_range=(0, 360),
|
central_rotation_range: Tuple[float, float] = (0, 360),
|
||||||
vertical_rotation_range=(-90, 10),
|
vertical_rotation_range: Tuple[float, float] = (-80, 20),
|
||||||
focal_range=(0.75, 1.35),
|
focal_range: Tuple[float, float] = (0.75, 1.35),
|
||||||
jitter_std=0.01,
|
jitter_std: float = 0.01,
|
||||||
|
center: Tuple[float, float, float] = (0, 0, 0),
|
||||||
):
|
):
|
||||||
"""generate random poses from an orbit camera
|
"""generate random poses from an orbit camera
|
||||||
Args:
|
Args:
|
||||||
size: batch size of generated poses.
|
size: batch size of generated poses.
|
||||||
device: where to allocate the output.
|
device: where to allocate the output.
|
||||||
radius: camera radius
|
radius_mean: mean radius of the orbit camera.
|
||||||
|
radius_std: standard deviation of the radius of the orbit camera.
|
||||||
central_rotation_range: amount that we rotate around the center of the object
|
central_rotation_range: amount that we rotate around the center of the object
|
||||||
vertical_rotation_range: amount that we allow the cameras to pan up and down from horizontal
|
vertical_rotation_range: amount that we allow the cameras to pan up and down from horizontal
|
||||||
|
focal_range: focal length range
|
||||||
|
jitter_std: standard deviation of the jitter added to the camera position
|
||||||
|
center: center of the object
|
||||||
Return:
|
Return:
|
||||||
poses: [size, 4, 4]
|
poses: [size, 4, 4]
|
||||||
"""
|
"""
|
||||||
@@ -120,7 +125,11 @@ def random_train_pose(
|
|||||||
origins = torch.stack([torch.tensor([0, 0, 1])] * size, dim=0)
|
origins = torch.stack([torch.tensor([0, 0, 1])] * size, dim=0)
|
||||||
origins = (origins * radius_mean) + (origins * (torch.randn((origins.shape)) * radius_std))
|
origins = (origins * radius_mean) + (origins * (torch.randn((origins.shape)) * radius_std))
|
||||||
R = torch.bmm(rot_z, rot_x) # Want to have Rx @ Ry @ origin
|
R = torch.bmm(rot_z, rot_x) # Want to have Rx @ Ry @ origin
|
||||||
t = torch.bmm(R, origins.unsqueeze(-1)) + torch.randn((size, 3, 1)) * jitter_std
|
t = (
|
||||||
|
torch.bmm(R, origins.unsqueeze(-1))
|
||||||
|
+ torch.randn((size, 3, 1)) * jitter_std
|
||||||
|
+ torch.tensor(center)[None, :, None]
|
||||||
|
)
|
||||||
camera_to_worlds = torch.cat([R, t], dim=-1)
|
camera_to_worlds = torch.cat([R, t], dim=-1)
|
||||||
|
|
||||||
focals = torch.rand(size) * (focal_range[1] - focal_range[0]) + focal_range[0]
|
focals = torch.rand(size) * (focal_range[1] - focal_range[0]) + focal_range[0]
|
||||||
@@ -154,16 +163,17 @@ class DreamFusionDataManagerConfig(VanillaDataManagerConfig):
|
|||||||
"""Number of images per batch for training"""
|
"""Number of images per batch for training"""
|
||||||
eval_images_per_batch: int = 1
|
eval_images_per_batch: int = 1
|
||||||
"""Number of images per batch for evaluation"""
|
"""Number of images per batch for evaluation"""
|
||||||
radius_mean: float = 1.6
|
radius_mean: float = 2.2
|
||||||
"""Mean radius of camera orbit"""
|
"""Mean radius of camera orbit"""
|
||||||
radius_std: float = 0.2
|
radius_std: float = 0.1
|
||||||
"""Std of radius of camera orbit"""
|
"""Std of radius of camera orbit"""
|
||||||
focal_range: Tuple[float, float] = (0.75, 1.35)
|
focal_range: Tuple[float, float] = (0.6, 1.2)
|
||||||
"""Range of focal length"""
|
"""Range of focal length"""
|
||||||
vertical_rotation_range: Tuple[float, float] = (-90, 30)
|
vertical_rotation_range: Tuple[float, float] = (-80, 30)
|
||||||
"""Range of vertical rotation"""
|
"""Range of vertical rotation"""
|
||||||
jitter_std: float = 0.05
|
jitter_std: float = 0.05
|
||||||
"""Std of camera direction jitter, so we don't just point the cameras towards the center every time"""
|
"""Std of camera direction jitter, so we don't just point the cameras towards the center every time"""
|
||||||
|
center: Tuple[float, float, float] = (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
class DreamFusionDataManager(VanillaDataManager): # pylint: disable=abstract-method
|
class DreamFusionDataManager(VanillaDataManager): # pylint: disable=abstract-method
|
||||||
@@ -209,6 +219,7 @@ class DreamFusionDataManager(VanillaDataManager): # pylint: disable=abstract-me
|
|||||||
focal_range=self.config.focal_range,
|
focal_range=self.config.focal_range,
|
||||||
vertical_rotation_range=self.config.vertical_rotation_range,
|
vertical_rotation_range=self.config.vertical_rotation_range,
|
||||||
jitter_std=self.config.jitter_std,
|
jitter_std=self.config.jitter_std,
|
||||||
|
center=self.config.center,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.train_dataset = TrivialDataset(cameras)
|
self.train_dataset = TrivialDataset(cameras)
|
||||||
@@ -243,6 +254,7 @@ class DreamFusionDataManager(VanillaDataManager): # pylint: disable=abstract-me
|
|||||||
focal_range=self.config.focal_range,
|
focal_range=self.config.focal_range,
|
||||||
vertical_rotation_range=self.config.vertical_rotation_range,
|
vertical_rotation_range=self.config.vertical_rotation_range,
|
||||||
jitter_std=self.config.jitter_std,
|
jitter_std=self.config.jitter_std,
|
||||||
|
center=self.config.center,
|
||||||
)
|
)
|
||||||
ray_bundle = cameras.generate_rays(torch.tensor(list(range(self.config.train_images_per_batch)))).flatten()
|
ray_bundle = cameras.generate_rays(torch.tensor(list(range(self.config.train_images_per_batch)))).flatten()
|
||||||
|
|
||||||
@@ -264,6 +276,7 @@ class DreamFusionDataManager(VanillaDataManager): # pylint: disable=abstract-me
|
|||||||
focal_range=self.config.focal_range,
|
focal_range=self.config.focal_range,
|
||||||
vertical_rotation_range=self.config.vertical_rotation_range,
|
vertical_rotation_range=self.config.vertical_rotation_range,
|
||||||
jitter_std=self.config.jitter_std,
|
jitter_std=self.config.jitter_std,
|
||||||
|
center=self.config.center,
|
||||||
)
|
)
|
||||||
ray_bundle = cameras.generate_rays(
|
ray_bundle = cameras.generate_rays(
|
||||||
torch.tensor([[i] for i in range(self.config.train_images_per_batch)])
|
torch.tensor([[i] for i in range(self.config.train_images_per_batch)])
|
||||||
|
|||||||
@@ -41,10 +41,7 @@ from nerfstudio.model_components.losses import (
|
|||||||
orientation_loss,
|
orientation_loss,
|
||||||
pred_normal_loss,
|
pred_normal_loss,
|
||||||
)
|
)
|
||||||
from nerfstudio.model_components.ray_samplers import (
|
from nerfstudio.model_components.ray_samplers import ProposalNetworkSampler
|
||||||
ProposalNetworkSampler,
|
|
||||||
UniformSampler,
|
|
||||||
)
|
|
||||||
from nerfstudio.model_components.renderers import (
|
from nerfstudio.model_components.renderers import (
|
||||||
AccumulationRenderer,
|
AccumulationRenderer,
|
||||||
DepthRenderer,
|
DepthRenderer,
|
||||||
@@ -115,6 +112,10 @@ class DreamFusionModelConfig(ModelConfig):
|
|||||||
"""Proposal loss multiplier."""
|
"""Proposal loss multiplier."""
|
||||||
distortion_loss_mult: float = 1.0
|
distortion_loss_mult: float = 1.0
|
||||||
"""Distortion loss multiplier."""
|
"""Distortion loss multiplier."""
|
||||||
|
start_normals_training: int = 1000
|
||||||
|
"""Start training normals after this many iterations"""
|
||||||
|
start_lambertian_training: int = 1000
|
||||||
|
"""start training with lambertian shading after this many iterations"""
|
||||||
|
|
||||||
|
|
||||||
class DreamFusionModel(Model):
|
class DreamFusionModel(Model):
|
||||||
@@ -224,11 +225,9 @@ class DreamFusionModel(Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# anneal the weights of the proposal network before doing PDF sampling
|
# anneal the weights of the proposal network before doing PDF sampling
|
||||||
N = self.config.proposal_weights_anneal_max_num_iters
|
|
||||||
|
|
||||||
def set_anneal(step):
|
def set_anneal(step):
|
||||||
# https://arxiv.org/pdf/2111.12077.pdf eq. 18
|
# https://arxiv.org/pdf/2111.12077.pdf eq. 18
|
||||||
train_frac = np.clip(step / N, 0, 1)
|
train_frac = np.clip(step / self.config.proposal_weights_anneal_max_num_iters, 0, 1)
|
||||||
bias = lambda x, b: (b * x) / ((b - 1) * x + 1)
|
bias = lambda x, b: (b * x) / ((b - 1) * x + 1)
|
||||||
anneal = bias(train_frac, self.config.proposal_weights_anneal_slope)
|
anneal = bias(train_frac, self.config.proposal_weights_anneal_slope)
|
||||||
self.proposal_sampler.set_anneal(anneal)
|
self.proposal_sampler.set_anneal(anneal)
|
||||||
@@ -242,13 +241,13 @@ class DreamFusionModel(Model):
|
|||||||
),
|
),
|
||||||
TrainingCallback(
|
TrainingCallback(
|
||||||
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
||||||
iters=(1000,),
|
iters=(self.config.start_normals_training,),
|
||||||
func=start_training_normals,
|
func=start_training_normals,
|
||||||
args=[self, training_callback_attributes],
|
args=[self, training_callback_attributes],
|
||||||
),
|
),
|
||||||
TrainingCallback(
|
TrainingCallback(
|
||||||
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
where_to_run=[TrainingCallbackLocation.AFTER_TRAIN_ITERATION],
|
||||||
iters=(1000,),
|
iters=(self.config.start_lambertian_training,),
|
||||||
func=start_shaded_training,
|
func=start_shaded_training,
|
||||||
args=[self, training_callback_attributes],
|
args=[self, training_callback_attributes],
|
||||||
),
|
),
|
||||||
@@ -273,6 +272,7 @@ class DreamFusionModel(Model):
|
|||||||
|
|
||||||
def get_param_groups(self) -> Dict[str, List[Parameter]]:
|
def get_param_groups(self) -> Dict[str, List[Parameter]]:
|
||||||
param_groups = {}
|
param_groups = {}
|
||||||
|
param_groups["proposal_networks"] = list(self.proposal_networks.parameters())
|
||||||
param_groups["fields"] = list(self.field.parameters())
|
param_groups["fields"] = list(self.field.parameters())
|
||||||
return param_groups
|
return param_groups
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ class DreamFusionModel(Model):
|
|||||||
background = accum_mask_inv * background_rgb
|
background = accum_mask_inv * background_rgb
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
"rgb": rgb,
|
"rgb_only": rgb,
|
||||||
"background_rgb": background_rgb,
|
"background_rgb": background_rgb,
|
||||||
"background": background,
|
"background": background,
|
||||||
"accumulation": accum_mask,
|
"accumulation": accum_mask,
|
||||||
@@ -343,7 +343,7 @@ class DreamFusionModel(Model):
|
|||||||
outputs["pred_normals"] = self.shader_normals(pred_normals, weights=accum_mask)
|
outputs["pred_normals"] = self.shader_normals(pred_normals, weights=accum_mask)
|
||||||
outputs["shaded"] = accum_mask * shaded + torch.ones_like(shaded) * accum_mask_inv
|
outputs["shaded"] = accum_mask * shaded + torch.ones_like(shaded) * accum_mask_inv
|
||||||
outputs["shaded_albedo"] = shaded_albedo
|
outputs["shaded_albedo"] = shaded_albedo
|
||||||
outputs["render"] = accum_mask * rgb + background
|
outputs["rgb"] = accum_mask * rgb + background
|
||||||
|
|
||||||
if shading_weight < 0:
|
if shading_weight < 0:
|
||||||
if np.random.random_sample() > 0.5:
|
if np.random.random_sample() > 0.5:
|
||||||
@@ -351,7 +351,7 @@ class DreamFusionModel(Model):
|
|||||||
else:
|
else:
|
||||||
outputs["train_output"] = accum_mask * shaded_albedo + background
|
outputs["train_output"] = accum_mask * shaded_albedo + background
|
||||||
else:
|
else:
|
||||||
outputs["train_output"] = outputs["render"]
|
outputs["train_output"] = outputs["rgb"]
|
||||||
|
|
||||||
if self.training or True:
|
if self.training or True:
|
||||||
outputs["rendered_orientation_loss"] = orientation_loss(
|
outputs["rendered_orientation_loss"] = orientation_loss(
|
||||||
@@ -411,7 +411,21 @@ class DreamFusionModel(Model):
|
|||||||
outputs["depth"],
|
outputs["depth"],
|
||||||
accumulation=outputs["accumulation"],
|
accumulation=outputs["accumulation"],
|
||||||
)
|
)
|
||||||
|
prop_depth_0 = colormaps.apply_depth_colormap(
|
||||||
|
outputs["prop_depth_0"],
|
||||||
|
accumulation=outputs["accumulation"],
|
||||||
|
)
|
||||||
|
prop_depth_1 = colormaps.apply_depth_colormap(
|
||||||
|
outputs["prop_depth_1"],
|
||||||
|
accumulation=outputs["accumulation"],
|
||||||
|
)
|
||||||
|
|
||||||
metrics_dict = {}
|
metrics_dict = {}
|
||||||
images_dict = {"img": outputs["rgb"], "accumulation": acc, "depth": depth}
|
images_dict = {
|
||||||
|
"img": outputs["rgb"],
|
||||||
|
"accumulation": acc,
|
||||||
|
"depth": depth,
|
||||||
|
"prop_depth_0": prop_depth_0,
|
||||||
|
"prop_depth_1": prop_depth_1,
|
||||||
|
}
|
||||||
return metrics_dict, images_dict
|
return metrics_dict, images_dict
|
||||||
@@ -237,9 +237,6 @@ class NerfactoModel(Model):
|
|||||||
return callbacks
|
return callbacks
|
||||||
|
|
||||||
def get_outputs(self, ray_bundle: RayBundle):
|
def get_outputs(self, ray_bundle: RayBundle):
|
||||||
print(ray_bundle.shape)
|
|
||||||
if not self.training:
|
|
||||||
raise
|
|
||||||
ray_samples, weights_list, ray_samples_list = self.proposal_sampler(ray_bundle, density_fns=self.density_fns)
|
ray_samples, weights_list, ray_samples_list = self.proposal_sampler(ray_bundle, density_fns=self.density_fns)
|
||||||
field_outputs = self.field(ray_samples, compute_normals=self.config.predict_normals)
|
field_outputs = self.field(ray_samples, compute_normals=self.config.predict_normals)
|
||||||
weights = ray_samples.get_weights(field_outputs[FieldHeadNames.DENSITY])
|
weights = ray_samples.get_weights(field_outputs[FieldHeadNames.DENSITY])
|
||||||
|
|||||||
Reference in new issue
Block a user