Repository: nerfstudio-project/nerfstudio

Issue:
instant-ngp render error 
Hi

I was able to render fine with instant-ngp but I updated to the latest code (last week) and now instant-ngp fails to render

here is the shell error

```
> ns-render --load-config ... --traj filename --camera-path-filename ...
[21:59:33] Auto image downscale factor of 1                                                 nerfstudio_dataparser.py:290
[21:59:35] Skipping 0 files in dataset split train.                                         nerfstudio_dataparser.py:147
           Skipping 0 files in dataset split test.                                          nerfstudio_dataparser.py:147
None
Traceback (most recent call last):
  File "nerf-studio/nerfstudio/scripts/render_exr.py", line 180, in <module>
    entrypoint()
  File "nerf-studio/nerfstudio/scripts/render_exr.py", line 176, in entrypoint
    tyro.cli(RenderTrajectory).main()
  File "nerf-studio/nerfstudio/scripts/render_exr.py", line 142, in main
    test_mode="test" if self.traj == "spiral" else "inference",
  File "nerf-studio/nerfstudio/utils/eval_utils.py", line 100, in eval_setup
    pipeline = config.pipeline.setup(device=device, test_mode=test_mode)
  File "nerf-studio/nerfstudio/configs/base_config.py", line 66, in setup
    return self._target(self, **kwargs)
  File "nerf-studio/nerfstudio/pipelines/dynamic_batch.py", line 63, in __init__
    self._update_pixel_samplers()
  File "nerf-studio/nerfstudio/pipelines/dynamic_batch.py", line 67, in _update_pixel_samplers
    self.datamanager.train_pixel_sampler.set_num_rays_per_batch(self.dynamic_num_rays_per_batch)
  File "nerf-studio/venv3.7_nerfstudio/lib64/python3.7/site-packages/torch/nn/modules/module.py", line 1208, in __getattr__
    type(self).__name__, name))
AttributeError: 'VanillaDataManager' object has no attribute 'train_pixel_sampler'
```

let me know if you spot something obvious

thanks for your help


Discussion:
One thing I have found is that sometimes nerfstudio version changes are not backward compatible with prior training outputs.
Was your config trained with a prior version?  If so, you may need to retrain for this version to be able to render or export.
Thanks for your reply machenmusik. Unfortunately, it was a brand new training.

Resolving patch:
diff --git a/nerfstudio/data/datamanagers/base_datamanager.py b/nerfstudio/data/datamanagers/base_datamanager.py
--- a/nerfstudio/data/datamanagers/base_datamanager.py
+++ b/nerfstudio/data/datamanagers/base_datamanager.py
@@ -298,6 +298,8 @@ class VanillaDataManager(DataManager):  # pylint: disable=abstract-method
     train_dataset: InputDataset
     eval_dataset: InputDataset
     train_dataparser_outputs: DataparserOutputs
+    train_pixel_sampler: Optional[PixelSampler] = None
+    eval_pixel_sampler: Optional[PixelSampler] = None
 
     def __init__(
         self,
@@ -408,6 +410,7 @@ def next_train(self, step: int) -> Tuple[RayBundle, Dict]:
         """Returns the next batch of data from the train dataloader."""
         self.train_count += 1
         image_batch = next(self.iter_train_image_dataloader)
+        assert self.train_pixel_sampler is not None
         batch = self.train_pixel_sampler.sample(image_batch)
         ray_indices = batch["indices"]
         ray_bundle = self.train_ray_generator(ray_indices)
@@ -417,6 +420,7 @@ def next_eval(self, step: int) -> Tuple[RayBundle, Dict]:
         """Returns the next batch of data from the eval dataloader."""
         self.eval_count += 1
         image_batch = next(self.iter_eval_image_dataloader)
+        assert self.eval_pixel_sampler is not None
         batch = self.eval_pixel_sampler.sample(image_batch)
         ray_indices = batch["indices"]
         ray_bundle = self.eval_ray_generator(ray_indices)
diff --git a/nerfstudio/pipelines/dynamic_batch.py b/nerfstudio/pipelines/dynamic_batch.py
--- a/nerfstudio/pipelines/dynamic_batch.py
+++ b/nerfstudio/pipelines/dynamic_batch.py
@@ -64,8 +64,10 @@ def __init__(
 
     def _update_pixel_samplers(self):
         """Update the pixel samplers for train and eval with the dynamic number of rays per batch."""
-        self.datamanager.train_pixel_sampler.set_num_rays_per_batch(self.dynamic_num_rays_per_batch)
-        self.datamanager.eval_pixel_sampler.set_num_rays_per_batch(self.dynamic_num_rays_per_batch)
+        if self.datamanager.train_pixel_sampler is not None:
+            self.datamanager.train_pixel_sampler.set_num_rays_per_batch(self.dynamic_num_rays_per_batch)
+        if self.datamanager.eval_pixel_sampler is not None:
+            self.datamanager.eval_pixel_sampler.set_num_rays_per_batch(self.dynamic_num_rays_per_batch)
 
     def _update_dynamic_num_rays_per_batch(self, num_samples_per_batch: int):
         """Updates the dynamic number of rays per batch variable,


Test patch: