-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in pixel sampler #3103
Fix bug in pixel sampler #3103
Conversation
Would it be simpler if we change the loop |
It would still fail due to getting a negative number of rays for the last image you loop over, no? Or do you propose to skip the last image in that case? Then you would end up with more rays than expected for the batch, which doesn't sound like desired behavior. Perhaps I misunderstood your suggestion. :) |
My read of the current code is current sampling will undersample the first (num_images - 1) images, and might return a number greater than The main issue is this line:
which would cause the last image number to be negative. What if we just remove this part of code? Why the num_rays_in_batch must be even? I was thinking oversample last image is problematic, we can do a shuffling of the image indices each time we sample rays. |
According to the latest fix to this file, num_rays_in_batch needs to be divisible by 2 for depth nerfacto to work: #2939 Current code will oversample the first (num_images - 1) images, no? For example, let's say you have specified 4096 rays per batch and have 240 images. Ideally, you'd like to sample 17.067 rays per image (which is impossible of course). The current code will instead sample 18 rays per image. The first 239 images will then add up to 4306 rays, which is more than we desire and thus result in a negative number of rays on the last image. If you instead wish to undersample the first (num_images - 1), i.e by doing
you would end up oversampling the last image. When the number of images grow, so will the number of rays for the last image. |
@carlinds Thanks for the explanation! now I have better understanding of what this PR solves. I have some additional comments (see above). |
d9391f9
to
664286b
Compare
@jb-ye Which comments are you referring to? I couldn't find any comments on the commit. |
I have inline comments here: Also could you refactor this section of code to a separate function? you also need to run the formatter to pass core tests and make the PR ready to merge.
|
Do we need to support the case where num_rays_per_batch is odd? Naturally, it can't be divided into even chunks so we would either need to handle it by changing it to the closest even number or simply assert and inform the user. As it's a user-specified argument I would prefer an assert. |
33145f7
to
e7ab806
Compare
Current sampling will oversample the first (num_images - 1) images, and might return a negative number of rays for the last image. The proposed fix finds an optimal ratio of rays per image such that the constraint of always being divisible by 2 is still satisfied.