nerfstudio-project / nerfstudio

A collaboration friendly studio for NeRFs
https://docs.nerf.studio
Apache License 2.0
9.31k stars 1.26k forks source link

AttributeError: 'NerfactoModelConfig' object has no attribute 'camera_optimizer' #3012

Open qiyang77 opened 6 months ago

qiyang77 commented 6 months ago

I trained the model in Windows and now I want to conduct the inference in Linux. However, model initialization was failed. nerfstudio version is 1.0.2, python version is 3.10 Any ideas?

Cell In[32], line 428, in init_mainModel(project)
    426 config = yaml.load(configPath.read_text(), Loader=yaml.Loader)
    427 print(config)
--> 428 _, pipeline, _, _ = eval_setup(
    429     configPath,
    430     eval_num_rays_per_chunk=None,
    431     test_mode="inference",
    432 )
    434 return original_coordinates, nerf_coordinates, utm_coordinates, combined_scale, scale_nerf, scale_subplot, shift, avg_pos_subplot, pipeline

File /panfs/jay/groups/15/jinzn/yang8460/nerfstudio/nerfstudio/utils/eval_utils.py:105, in eval_setup(config_path, eval_num_rays_per_chunk, test_mode, update_config_callback)
    103 # setup pipeline (which includes the DataManager)
    104 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
--> 105 pipeline = config.pipeline.setup(device=device, test_mode=test_mode)
    106 assert isinstance(pipeline, Pipeline)
    107 pipeline.eval()

File /panfs/jay/groups/15/jinzn/yang8460/nerfstudio/nerfstudio/configs/base_config.py:54, in InstantiateConfig.setup(self, **kwargs)
     52 def setup(self, **kwargs) -> Any:
     53     """Returns the instantiated object using the config."""
---> 54     return self._target(self, **kwargs)

File /panfs/jay/groups/15/jinzn/yang8460/nerfstudio/nerfstudio/pipelines/base_pipeline.py:270, in VanillaPipeline.__init__(self, config, device, test_mode, world_size, local_rank, grad_scaler)
    267 # TODO(ethan): get rid of scene_bounds from the model
    268 assert self.datamanager.train_dataset is not None, "Missing input dataset"
--> 270 self._model = config.model.setup(
    271     scene_box=self.datamanager.train_dataset.scene_box,
    272     num_train_data=len(self.datamanager.train_dataset),
    273     metadata=self.datamanager.train_dataset.metadata,
    274     device=device,
    275     grad_scaler=grad_scaler,
    276     seed_points=seed_pts,
    277 )
    278 self.model.to(device)
    280 self.world_size = world_size

File /panfs/jay/groups/15/jinzn/yang8460/nerfstudio/nerfstudio/configs/base_config.py:54, in InstantiateConfig.setup(self, **kwargs)
     52 def setup(self, **kwargs) -> Any:
     53     """Returns the instantiated object using the config."""
---> 54     return self._target(self, **kwargs)

File /panfs/jay/groups/15/jinzn/yang8460/nerfstudio/nerfstudio/models/base_model.py:85, in Model.__init__(self, config, scene_box, num_train_data, **kwargs)
     82 self.kwargs = kwargs
     83 self.collider = None
---> 85 self.populate_modules()  # populate the modules
     86 self.callbacks = None
     87 # to keep track of which device the nn.Module is on

File /panfs/jay/groups/15/jinzn/yang8460/nerfstudio/nerfstudio/models/nerfacto.py:175, in NerfactoModel.populate_modules(self)
    155 # Fields
    156 self.field = NerfactoField(
    157     self.scene_box.aabb,
    158     hidden_dim=self.config.hidden_dim,
   (...)
    172     implementation=self.config.implementation,
    173 )
--> 175 self.camera_optimizer: CameraOptimizer = self.config.camera_optimizer.setup(
    176     num_cameras=self.num_train_data, device="cpu"
    177 )
    178 self.density_fns = []
    179 num_prop_nets = self.config.num_proposal_iterations

AttributeError: 'NerfactoModelConfig' object has no attribute 'camera_optimizer'
kerrj commented 6 months ago

That's strange, maybe the result of a bad merge? It should be defined here: https://github.com/nerfstudio-project/nerfstudio/blob/12195f034f51e229bb9bef3b99925d48979b4a6f/nerfstudio/models/nerfacto.py#L131

qiyang77 commented 6 months ago

Dear kerrj, thanks for your response! I may have some clues, the model was trained by nerfstudio 0.3.4 and in that version there is no definition of the camera_optimizer in the "nerfstudio/nerfstudio/models/nerfacto.py".

Now I am using nerfstudio v1.0.2 to load the model, and it looks like some new features didn't be initialized. I print out the "self.config" before this line, and these is indeed no property named "camera_optimizer".

https://github.com/nerfstudio-project/nerfstudio/blob/12195f034f51e229bb9bef3b99925d48979b4a6f/nerfstudio/models/nerfacto.py#L175

NerfactoModelConfig:
    _target: <class 'nerfstudio.models.nerfacto.NerfactoModel'>
    appearance_embed_dim: 32
    background_color: last_sample
    base_res: 16
    collider_params: {'far_plane': 6.0, 'near_plane': 2.0}
    disable_scene_contraction: False
    distortion_loss_mult: 0.002
    enable_collider: True
    eval_num_rays_per_chunk: 32768
    far_plane: 1000.0
    features_per_level: 2
    hidden_dim: 64
    hidden_dim_color: 64
    hidden_dim_transient: 64
    implementation: tcnn
    interlevel_loss_mult: 1.0
    log2_hashmap_size: 19
    loss_coefficients: {'rgb_loss_coarse': 1.0, 'rgb_loss_fine': 1.0}
    max_res: 2048
    near_plane: 0.05
    num_levels: 16
    num_nerf_samples_per_ray: 48
    num_proposal_iterations: 2
    num_proposal_samples_per_ray: [256
    96]
    orientation_loss_mult: 0.0001
    pred_normal_loss_mult: 0.001
    predict_normals: False
    prompt: None
    proposal_initial_sampler: piecewise
    proposal_net_args_list: [{'hidden_dim': 16, 'log2_hashmap_size': 17, 'max_res': 128, 'num_levels': 5, 'use_linear': False}, {'hidden_dim': 16, 'log2_hashmap_size': 17, 'max_res': 256, 'num_levels': 5, 'use_linear': False}]
    proposal_update_every: 5
    proposal_warmup: 5000
    proposal_weights_anneal_max_num_iters: 1000
    proposal_weights_anneal_slope: 10.0
    use_average_appearance_embedding: True
    use_gradient_scaling: False
    use_proposal_weight_anneal: True
    use_same_proposal_network: False
    use_single_jitter: True

Could this be caused by the difference in .yaml files?

samcao0416 commented 5 months ago

Thank you guys. Same problem here. However, I met the issue only when I was rendering the nerfacto-big model. Nerfacto and nerfacto-huge were fine. I trained them with the same version of nerfstudio(1.0.1). I checked the config files, they are the same. I also tried to update the version of ns-studio to 1.0.2, and the problem still occurs.