From 169d02458404a15fb0bf0d7172ce31e27f9716fa Mon Sep 17 00:00:00 2001 From: Kushashwa Ravi Shrimali Date: Thu, 30 Jun 2022 15:35:09 +0530 Subject: [PATCH 1/4] Support NP_EXTENSIONS for SemanticSegmentationFilesInput --- flash/image/segmentation/input.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flash/image/segmentation/input.py b/flash/image/segmentation/input.py index 6a3c66e6be..78f302d872 100644 --- a/flash/image/segmentation/input.py +++ b/flash/image/segmentation/input.py @@ -21,7 +21,7 @@ from flash.core.data.utilities.samples import to_samples from flash.core.integrations.fiftyone.utils import FiftyOneLabelUtilities from flash.core.utilities.imports import _FIFTYONE_AVAILABLE, _TORCHVISION_AVAILABLE, lazy_import -from flash.image.data import image_loader, ImageDeserializer, IMG_EXTENSIONS +from flash.image.data import image_loader, ImageDeserializer, IMG_EXTENSIONS, NP_EXTENSIONS from flash.image.segmentation.output import SegmentationLabelsOutput if _FIFTYONE_AVAILABLE: @@ -97,9 +97,9 @@ def load_data( ) -> List[Dict[str, Any]]: self.load_labels_map(num_classes, labels_map) if mask_files is None: - files = filter_valid_files(files, valid_extensions=IMG_EXTENSIONS) + files = filter_valid_files(files, valid_extensions=IMG_EXTENSIONS + NP_EXTENSIONS) else: - files, mask_files = filter_valid_files(files, mask_files, valid_extensions=IMG_EXTENSIONS) + files, mask_files = filter_valid_files(files, mask_files, valid_extensions=IMG_EXTENSIONS + NP_EXTENSIONS) return to_samples(files, mask_files) def load_sample(self, sample: Dict[str, Any]) -> Dict[str, Any]: From a7d8a5a59b3dce4948f882e53d0a5a2195951232 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 18:25:19 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- flash/image/segmentation/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flash/image/segmentation/input.py b/flash/image/segmentation/input.py index 8604969629..20efdc4cf6 100644 --- a/flash/image/segmentation/input.py +++ b/flash/image/segmentation/input.py @@ -17,7 +17,7 @@ import torch from flash.core.data.io.input import DataKeys, Input -from flash.core.data.utilities.loading import IMG_EXTENSIONS, NP_EXTENSIONS, load_image +from flash.core.data.utilities.loading import IMG_EXTENSIONS, load_image, NP_EXTENSIONS from flash.core.data.utilities.paths import filter_valid_files, PATH_TYPE from flash.core.data.utilities.samples import to_samples from flash.core.integrations.fiftyone.utils import FiftyOneLabelUtilities From 6fb67cdbf0e776094fa9969c262b58e6eb8fd33d Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Thu, 14 Jul 2022 20:12:16 +0100 Subject: [PATCH 3/4] Fixes --- flash/core/data/utilities/loading.py | 2 +- flash/image/segmentation/data.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flash/core/data/utilities/loading.py b/flash/core/data/utilities/loading.py index a466add7eb..b0bc0180e0 100644 --- a/flash/core/data/utilities/loading.py +++ b/flash/core/data/utilities/loading.py @@ -70,7 +70,7 @@ def _load_image_from_image(file, drop_alpha: bool = True): def _load_image_from_numpy(file): - return Image.fromarray(np.load(file).astype("uint8"), "RGB") + return Image.fromarray(np.load(file).astype("uint8")).convert("RGB") def _load_spectrogram_from_image(file): diff --git a/flash/image/segmentation/data.py b/flash/image/segmentation/data.py index 66d07d46a0..12465c3f3d 100644 --- a/flash/image/segmentation/data.py +++ b/flash/image/segmentation/data.py @@ -115,9 +115,9 @@ def from_files( >>> from PIL import Image >>> rand_image = Image.fromarray(np.random.randint(0, 255, (64, 64, 3), dtype="uint8")) - >>> rand_mask= Image.fromarray(np.random.randint(0, 10, (64, 64), dtype="uint8")) + >>> rand_mask= np.random.randint(0, 10, (64, 64), dtype="uint8") >>> _ = [rand_image.save(f"image_{i}.png") for i in range(1, 4)] - >>> _ = [rand_mask.save(f"mask_{i}.png") for i in range(1, 4)] + >>> _ = [np.save(f"mask_{i}.npy", rand_mask) for i in range(1, 4)] >>> _ = [rand_image.save(f"predict_image_{i}.png") for i in range(1, 4)] .. doctest:: @@ -126,7 +126,7 @@ def from_files( >>> from flash.image import SemanticSegmentation, SemanticSegmentationData >>> datamodule = SemanticSegmentationData.from_files( ... train_files=["image_1.png", "image_2.png", "image_3.png"], - ... train_targets=["mask_1.png", "mask_2.png", "mask_3.png"], + ... train_targets=["mask_1.npy", "mask_2.npy", "mask_3.npy"], ... predict_files=["predict_image_1.png", "predict_image_2.png", "predict_image_3.png"], ... transform_kwargs=dict(image_size=(128, 128)), ... num_classes=10, @@ -145,7 +145,7 @@ def from_files( >>> import os >>> _ = [os.remove(f"image_{i}.png") for i in range(1, 4)] - >>> _ = [os.remove(f"mask_{i}.png") for i in range(1, 4)] + >>> _ = [os.remove(f"mask_{i}.npy") for i in range(1, 4)] >>> _ = [os.remove(f"predict_image_{i}.png") for i in range(1, 4)] """ From 496de60d3bf36140b924a33fd4598f773d7890df Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Thu, 14 Jul 2022 20:13:58 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcc17a414a..eb1e945ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed a bug where the `processor_backbone` argument to `SpeechRecognition` was not used for decoding outputs ([#1362](https://github.com/PyTorchLightning/lightning-flash/pull/1362)) +- Fixed a bug where `.npy` files could not be used with `SemanticSegmentationData` ([#1369](https://github.com/PyTorchLightning/lightning-flash/pull/1369)) + ## [0.7.4] - 2022-04-27 ### Fixed