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

Fix for Blank Images in plot due to Float Tensor Ranges #1712

Merged
merged 2 commits into from
Nov 6, 2023

Conversation

menglutao
Copy link
Contributor

Description:
Encountered an issue where ucmerced dataset images would render as blank after using the plot function and matplotlib to show the image.

Issue:
The underlying cause is that Matplotlib expects float values to be normalized between 0 and 1. However, the float tensor representing our image data occasionally contained values in the 0 to 255 range, leading to unexpected behavior in the rendering process.

Resolution:
A conditional check has been introduced. When the maximum value in the image tensor exceeds 1, the tensor is normalized by scaling down to the 0 to 1 range. This ensures compatibility with Matplotlib's expected float value range and resolves the issue of blank images.

Outcome:
With the proposed changes, images are displayed correctly, regardless of whether their data originally spans 0 to 1 or 0 to 255.

I invite the maintainers to review the changes. Please advise if further modifications are required or if the update can be merged.

@github-actions github-actions bot added the datasets Geospatial or benchmark datasets label Nov 4, 2023
@adamjstewart adamjstewart added this to the 0.5.1 milestone Nov 5, 2023
@adamjstewart
Copy link
Collaborator

This relates to #1263. Depending on whether or not normalization is added, all of our plotting breaks. A better solution would be to implement the ideas in #1263, but that's a lot of work.

Looking through the data, it seems like every image is in the range 0–255. Until we implement #1263, it may be simpler just to always divide by 255.

@calebrob6
Copy link
Member

calebrob6 commented Nov 5, 2023

Let's merge this as plotting of images on tensorboard is indeed broken

@adamjstewart
Copy link
Collaborator

Doesn't tensorboard use the data module that includes normalization which divides all images by 255? If there are images with values greater than 255 that's a whole nother problem.

@adamjstewart
Copy link
Collaborator

Just checked and there are none greater than 255. So yes, data module plotting is broken, just like for every other dataset. We really need #1263 if we want both dataset plotting and data module plotting to work.

Copy link
Collaborator

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

Let's merge this for now and think about how we want to fix all other datasets in a separate PR. Thanks for the contribution!

@adamjstewart adamjstewart merged commit b6921fe into microsoft:main Nov 6, 2023
21 checks passed
nilsleh pushed a commit that referenced this pull request Nov 6, 2023
* fix: blank image when using plot

* black check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasets Geospatial or benchmark datasets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants