From d1e5a0e70dfc48d7b02f18d46e186d3c305931da Mon Sep 17 00:00:00 2001 From: MengluTao Date: Mon, 6 Nov 2023 12:42:30 +0100 Subject: [PATCH] Fix for Blank Images in plot due to Float Tensor Ranges (#1712) * fix: blank image when using plot * black check --- torchgeo/datasets/ucmerced.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/torchgeo/datasets/ucmerced.py b/torchgeo/datasets/ucmerced.py index 68e9dcb30c7..5e1b89aca03 100644 --- a/torchgeo/datasets/ucmerced.py +++ b/torchgeo/datasets/ucmerced.py @@ -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]