-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
PSNR implementation #2483
PSNR implementation #2483
Conversation
Hello @InCogNiTo124! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-07-08 08:24:51 UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a test and compare it to some standard lib like https://scikit-image.org/docs/stable/api/skimage.measure.html#compare-psnr
# Since mean and variance are unknown, we cannot know what's the maximum value to use in calculation. | ||
# This implementation, therefore, finds the maximum empirically. | ||
maximum = max(torch.max(torch.abs(pred)), torch.max(torch.abs(target))) | ||
PSNR_base_e = 2*torch.log(maximum) - torch.log(mse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable names should always be lowercase according to pep8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
I've added tests and I validated them with |
add such validation test with |
I wanted to, but I came to the conclusion that |
it is fine to add |
You should add |
I'm having trouble figuring out how to test with random inputs, I don't know how do I pass randomly generated tensors from
Sure :D |
Codecov Report
@@ Coverage Diff @@
## master #2483 +/- ##
=======================================
- Coverage 89% 87% -2%
=======================================
Files 69 70 +1
Lines 5518 5648 +130
=======================================
+ Hits 4889 4919 +30
- Misses 629 729 +100 |
I totally missed it, it should be fixed now :) |
if self.data_range is None: | ||
data_range = max(target.max() - target.min(), pred.max() - pred.min()) | ||
else: | ||
data_range = torch.tensor(float(self.data_range)) | ||
mse = F.mse_loss(pred.view(-1), target.view(-1)) | ||
# numerical precision tricks | ||
psnr_base_e = 2 * torch.log(data_range) - torch.log(mse) | ||
return psnr_base_e * (10 / torch.log(self.base)) # change the logarithm basis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to replicate the whole procedure again here. Just import from functional and use that one. :) Also add reduction
parameter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored and added
BTW in case you didn't know, pytest
says 'elementwise_mean'
is deprecated, it might be smart to refactor the default to 'mean'
. I left it that way to match rohitgr7's PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Also, can you fix the pep8 issues mentioned above by @pep8speaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohitgr7 I'm confused about the missing whitespace. I thought that was a bad thing :|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, don't know about that :| I never use an extra ,
after the last element in the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm I figured what was wrong
I've got a few failing tests I don't know how to fix:
|
@InCogNiTo124 I'm pretty sure you need to add it also to environment.yml |
Lift numpy to 1.16.4 in requirements/base.txt, this was fixed in this version. |
If you could add a test similar to https://github.com/PyTorchLightning/pytorch-lightning/blob/a91b06ed1e5295efecdd7b51f4a3e6d95c829ecd/tests/metrics/functional/test_classification.py#L38-L72 to test on random tensors:
|
@SkafteNicki you mean alongside or instead of these tests I already wrote? |
Just add a new test :) |
I googled the error in the TPU test, it seems that |
Pls ignore TPU test for this moment, the issue is related to forked PRs... cc: @zcain117 |
In that case, this seems done then :) |
Could you update CHANGELOG? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
What does this PR do?
Implements a new metric: PSNR (peak signal to noise ratio)
Fixes #2474
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃