Skip to content
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

Added compatibility with uint8 to SSIM metric #3045

Merged
merged 6 commits into from
Sep 13, 2023

Conversation

MarcBresson
Copy link
Contributor

Add compatibility and tests for when y_pred and y are in uint8 dtype

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions bot added the module: metrics Metrics module label Aug 24, 2023
Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this PR @MarcBresson !
I left a comment on how I would tackle this dtype problem.
I also label this PR with "help wanted" label to create a thread on our discord, where we could discuss about this PR in a more fluent way =>
EDIT: "Discuss "help-wanted" PR on Discord / discord (pull_request)" didn't work unfortunately, we'll see that later. However, if you would like to discuss this topic on discord, here is the link to the server: https://pytorch-ignite.ai/chat

Comment on lines 163 to 166
if self.data_range != 255:
warnings.warn(
"dtypes of the input tensors are torch.uint8 but data range is not set to 255.", RuntimeWarning
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of showing a warning in this case. I would follow the same strategy as skimage where they just transform to floating point. So, I would do the following:

if not y.is_floating_point():
    y = y.float()
if not y_pred.is_floating_point():
    y_pred = y_pred.float()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, as data_range is a required argument in ignite (while it has a default value in skiimg), the warning is not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put a default value to the data_range argument too? Most of the time we are dealing with [0; 1] images.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have a strong opinion on this. We have to figure out if there wont be any negative impact for the users in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the skiimg approach is quite good: default to data_range = 1.0, and warn if the detected type is of integer and that data range is still set to 1

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Aug 28, 2023

@MarcBresson can you please resolve the conflict and let's apply what we discussed up to here: #3045 (comment)
Concerning default to data_range = 1.0, let's keep the public API the same for now.

Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MarcBresson , LGTM!

@vfdev-5 vfdev-5 changed the title feat: add compatibility with uint8 Added compatibility with uint8 to SSIM metric Sep 13, 2023
@vfdev-5 vfdev-5 merged commit 8ec312c into pytorch:master Sep 13, 2023
15 of 17 checks passed
@MarcBresson
Copy link
Contributor Author

Sorry for the delay btw! Got caught up in a job seeking activity ahah

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 13, 2023

No worries, hope you can get something exciting as a new job role!

@MarcBresson MarcBresson deleted the feat-uint8-ssim branch September 13, 2023 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants