nerfstudio-project / gsplat

CUDA accelerated rasterization of gaussian splatting
https://docs.gsplat.studio/
Apache License 2.0
2.16k stars 273 forks source link

'Tensor' object has no attribute 'absgrad' #374

Open pjj123 opened 2 months ago

pjj123 commented 2 months ago

when use nerfstudio==1.1.3 and gsplat=1.0.0;

grads = self.xys.absgrad[0].norm(dim=-1) # type: ignore

error: File "/usr/local/lib/python3.8/dist-packages/nerfstudio/scripts/train.py", line 262, in entrypoint main( File "/usr/local/lib/python3.8/dist-packages/nerfstudio/scripts/train.py", line 247, in main launch( File "/usr/local/lib/python3.8/dist-packages/nerfstudio/scripts/train.py", line 189, in launch main_func(local_rank=0, world_size=world_size, config=config) File "/usr/local/lib/python3.8/dist-packages/nerfstudio/scripts/train.py", line 100, in train_loop trainer.train() File "/usr/local/lib/python3.8/dist-packages/nerfstudio/engine/trainer.py", line 265, in train callback.run_callback_at_location( File "/usr/local/lib/python3.8/dist-packages/nerfstudio/engine/callbacks.py", line 115, in run_callback_at_location self.run_callback(step=step) File "/usr/local/lib/python3.8/dist-packages/nerfstudio/engine/callbacks.py", line 105, in run_callback self.func(*self.args, self.kwargs, step=step) File "/home/jianjian-peng/code/street-gaussian/street_gaussians_ns/sgn_splatfacto.py", line 602, in aftertrain grads = self.xys.absgrad[0].detach().norm(dim=-1) AttributeError: 'Tensor' object has no attribute 'absgrad'**_

pjj123 commented 2 months ago

and rasterization(..., absgrad=True,...)

pjj123 commented 2 months ago

who can help me???

jckhng commented 2 months ago

Hi, I suggest you try to install gsplat=1.3.0 and try again?

You can refer to this: https://github.com/nerfstudio-project/gsplat/issues/362

JADGardner commented 2 months ago

I don't have a solution to this but wanted to add some information about where I also see this error.

I have encountered this issue but only when I modify the output of:

self.xys = info["means2d"]  # [1, N, 2] 

inside get_outputs of splatfacto here

In my current project I have two gaussian splat models; one for representing a scene and one for representing a person. I concatenate the guassian parameters together from both representations before rasterization. I then need to split apart 'means2d' for each representation after:


if all(item in self.reconstruction_mode for item in ['person', 'scene']):
    self.scene_rep.xys = info["means2d"][0:1, :num_scene_gaussians, :]  # [1, N, 2]
    self.scene_rep.radii = info["radii"][0, :num_scene_gaussians]  # [N]
    self.person_rep.xys = info["means2d"][0:1, num_scene_gaussians:, :]  # [1, K, 2]
    self.person_rep.radii = info["radii"][0, num_scene_gaussians:]  # [K]
elif 'scene' in self.reconstruction_mode:
    self.scene_rep.xys = info["means2d"]
    self.scene_rep.radii = info["radii"][0]
elif 'person' in self.reconstruction_mode:
    self.person_rep.xys = info["means2d"]
    self.person_rep.radii = info["radii"][0]

If you watch the values of either model.xys.absgrad during debugging they resolve as:

'AttributeError("'Tensor' object has no attribute 'absgrad'")'

Until the backwards pass is called in trainer.py

Then model.xys.absgrad resolves to a tensor with values.

For me, this works if I have self.reconstruction_mode as either 'scene' or 'person', i.e. I don't split info["means2d"].

However, if I split info["means2d"], as I do when I'm using both person_rep and scene_rep, then when the backwards pass is called neither the scene_rep.xys.absgrad or person_rep.xys.absgrad is updated and I get the same error as OP. It seems splitting info["means2d"] modifies the custom gradient computation in the backwards pass that would normally happen with absgrad=True.

starlordlxt commented 1 month ago

Hello! In gsplat.rasterization(), you may have to set absgrad = True. For more information you can refer to https://docs.gsplat.studio/main/apis/rasterization.html