-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add dim
to pytorch_lightning.metrics.PSNR
#5957
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5957 +/- ##
========================================
- Coverage 91% 33% -58%
========================================
Files 160 160
Lines 11313 11232 -81
========================================
- Hits 10272 3701 -6571
- Misses 1041 7531 +6490 |
@SkafteNicki |
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.
@SkafteNicki mind have look?
if data_range is None: | ||
if dim is not None: | ||
# Maybe we could use `torch.amax(target, dim=dim) - torch.amin(target, dim=dim)` in PyTorch 1.7 to calculate | ||
# `data_range` in the future. | ||
raise ValueError("`data_range` must be given when `dim` is not `None`.") | ||
|
||
data_range = target.max() - target.min() | ||
else: | ||
data_range = torch.tensor(float(data_range)) |
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.
could we move all this logic into the _update
function?
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.
In the original implementation (before this PR) and the updated commits (after the comment), the data_range
is passed to functional._psnr_compute
, maybe we could move the checks on data_range
and dim
from functional.psnr
and PSNR.__init__
to _compute
. But the users of PSNR
will get the exception until they call PSNR.compute
(or validation_epoch_end
is called).
Should we extract the logic to a single place (functional._psnr_compute
)?
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 ! Great contribution !
Hello @manipopopo! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-02-17 07:23:02 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.
LGTM
4cdafa7
to
a2d41a4
Compare
Co-authored-by: Jirka Borovec <[email protected]>
Change functional.psnr dim doc Co-authored-by: Nicki Skafte <[email protected]>
96e7387
to
d296919
Compare
What does this PR do?
Fixes #5933.
Suppose we have a batch containing two image pairs, the original
PSNR
calculates the mean-squared-error of the two pairs and then take thelog
to get the PSNR of the batch. By settingdim
, users can choose to calculate the _PSNR_s of the two pairs separately and then average the two _PSNR_s to get the score of the batch:Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃