TensoRF icon indicating copy to clipboard operation
TensoRF copied to clipboard

Wrong PSNR value by the in-place operator?

Open sangminkim-99 opened this issue 1 year ago • 6 comments

Hi, @apchenstu

Thank you for sharing this really great idea! It's very helpful for me to develop other ideas related to Radiance Fields.

By the way, I just notice that you might have wrong PSNR value by the in-place operator(+=). You've assigned the image loss variable loss to total_loss, and then increase it with the += operator. It will modify the original image loss loss variable resulting in wrong PSNR; in fact, smaller than the true value. You can check this at my colab.

Thank you, Sangmin Kim.

https://github.com/apchenstu/TensoRF/blob/17deeedae5ab4106b30a3295709ec3a8a654c7b1/train.py#L190-L198,

sangminkim-99 avatar Aug 03 '22 09:08 sangminkim-99

Hi, I think this only affects training PSNR, right?

Derry-Xing avatar Aug 11 '22 04:08 Derry-Xing

Hi, @Derry-Xing Yes, it is not related to the quality of the output images but only for the output PSNR values. I just want to check the reported PSNR at the paper is correct.

sangminkim-99 avatar Aug 11 '22 04:08 sangminkim-99

how come it affects the PSNR, the calculation of PSNR is related to this PSNRs.append(-10.0 * np.log(loss) / np.log(10.0)) it's about the variable loss, instead of total_loss, or did I miss something?

TIMESTICKING avatar Sep 06 '22 05:09 TIMESTICKING

how come it affects the PSNR, the calculation of PSNR is related to this PSNRs.append(-10.0 * np.log(loss) / np.log(10.0)) it's about the variable loss, instead of total_loss, or did I miss something?

At line 190, total loss shares the same memory with loss. Then any in-place operation on total_loss will modify the image loss term(loss in this code).

sangminkim-99 avatar Sep 06 '22 05:09 sangminkim-99

how come it affects the PSNR, the calculation of PSNR is related to this PSNRs.append(-10.0 * np.log(loss) / np.log(10.0)) it's about the variable loss, instead of total_loss, or did I miss something?

At line 190, total loss shares the same memory with loss. Then any in-place operation on total_loss will modify the image loss term(loss in this code).

thx, now I change it to

psnrloss = loss.clone().detach().item()
...
PSNRs.append(-10.0 * np.log(psnrloss ) / np.log(10.0))

is it correct now?

TIMESTICKING avatar Sep 06 '22 06:09 TIMESTICKING

how come it affects the PSNR, the calculation of PSNR is related to this PSNRs.append(-10.0 * np.log(loss) / np.log(10.0)) it's about the variable loss, instead of total_loss, or did I miss something?

At line 190, total loss shares the same memory with loss. Then any in-place operation on total_loss will modify the image loss term(loss in this code).

thx, now I change it to

psnrloss = loss.clone().detach().item()
...
PSNRs.append(-10.0 * np.log(psnrloss ) / np.log(10.0))

is it correct now?

Yes it seems good,

But i think you can just change the in-place operator; i.e. total_loss = total_loss + …

sangminkim-99 avatar Sep 06 '22 07:09 sangminkim-99