Fix for Blank Images in plot due to Float Tensor Ranges #1712
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.