NVIDIAGameWorks / kaolin-wisp

NVIDIA Kaolin Wisp is a PyTorch library powered by NVIDIA Kaolin Core to work with neural fields (including NeRFs, NGLOD, instant-ngp and VQAD).
Other
1.46k stars 131 forks source link

The input samples may not be normalized when the query method is called. #137

Closed wzy-99 closed 1 year ago

wzy-99 commented 1 year ago

https://github.com/NVIDIAGameWorks/kaolin-wisp/blob/28a99641c07c311aec98d54e65ed9a807ce4a59f/wisp/accelstructs/octree_as.py#L266

I have some questions about the following code:

        # Normalize between near and far plane
        depth *= (rays.dist_max - rays.dist_min)
        depth += rays.dist_min

        # Batched generation of samples
        # samples ~ (NUM_RAYS, NUM_SAMPLES, 3)
        # deltas, pidx, mask ~ (NUM_RAYS, NUM_SAMPLES)
        num_rays = rays.shape[0]
        samples = torch.addcmul(rays.origins[:, None], rays.dirs[:, None], depth[..., None])
        query_results = self.query(samples.reshape(num_rays * num_samples, 3), level=level)

I tested using the NeRF synthetic dataset and found that

rays.dist_max=6.0 
rays.dist_min=0
rays.origins[:, None] is not in the range -1 to 1

The input samples.reshape(num_rays * num_samples, 3) is also not in the range -1 to 1

But according to the document https://kaolin.readthedocs.io/en/latest/modules/kaolin.ops.spc.html?highlight=unbatched_query#kaolin.ops.spc.unbatched_query . The input query_coords need to be normalized in [-1, 1] if they are FloatTensor.

So is this a potential bug?

wzy-99 commented 1 year ago

I figured out that this step is to filter points outside the [-1,1] range. This means that the NeRF object should be located inside the cube in the center [-1,1].

orperel commented 1 year ago

You've got it just right :)

Found this little sketch from a while ago, for comparing how wisp normalizes coords v.s. i-ngp, in case this is useful to someone:

image

wzy-99 commented 1 year ago

Thank you for your answer. I understand better now!