ashawkey / torch-ngp

A pytorch CUDA extension implementation of instant-ngp (sdf and nerf), with a GUI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG?] GridEncoder doesn't give correct gradient with respect to the coordinate

zjumsj opened this issue · comments

@ashawkey My recent project requires the gradient with respect to the coordinate (inputs in code, BxD, D=3). However, the gradient returned seems incorrect. Only the first channel of grad_inputs has non-zero value. I guess the mistake is at line 143 in gridencoder.cu where only the first element of array pos_deriv is set to 1.0f. Hope that you can fix it if it's really a mistake.

    // calculate coordinate (always use float for precision!)
    float pos[D];
    float pos_deriv[D] = {1.0f}; // linear deriv is default to 1
    uint32_t pos_grid[D];
commented

@zjumsj You are right! Thanks for reporting this bug. It should have been fixed in c3fab17.

Thanks, I think it gives reasonable results now.