Skip to content

Commit

Permalink
Fix for Blank Images in plot due to Float Tensor Ranges (#1712)
Browse files Browse the repository at this point in the history
* fix: blank image when using plot

* black check
  • Loading branch information
menglutao authored and nilsleh committed Nov 6, 2023
1 parent 57b028c commit d1e5a0e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions torchgeo/datasets/ucmerced.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ def plot(
.. versionadded:: 0.2
"""
image = np.rollaxis(sample["image"].numpy(), 0, 3)

# Normalize the image if the max value is greater than 1
if image.max() > 1:
image = image.astype(np.float32) / 255.0 # Scale to [0, 1]

label = cast(int, sample["label"].item())
label_class = self.classes[label]

Expand Down

0 comments on commit d1e5a0e

Please sign in to comment.