-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sentinel2nccm datamodule on new branch (#1950)
* sentinel2nccm datamodule * Fixed style errors * added 2019 to sentinel2, removed 2022 from nccm * fixed error * Use matching split size --------- Co-authored-by: shreya28 <“[email protected]”> Co-authored-by: Adam J. Stewart <[email protected]>
- Loading branch information
1 parent
5a7b9e5
commit bd48efe
Showing
98 changed files
with
198 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
model: | ||
class_path: SemanticSegmentationTask | ||
init_args: | ||
loss: "ce" | ||
model: "unet" | ||
backbone: "resnet18" | ||
in_channels: 13 | ||
num_classes: 5 | ||
num_filters: 1 | ||
ignore_index: 4 | ||
data: | ||
class_path: Sentinel2NCCMDataModule | ||
init_args: | ||
batch_size: 2 | ||
patch_size: 16 | ||
dict_kwargs: | ||
nccm_paths: "tests/data/nccm" | ||
sentinel2_paths: "tests/data/sentinel2" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B01.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B02.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B03.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B04.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B05.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B06.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B07.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B08.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B09.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B10.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B11.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B12.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_B8A.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...0.SAFE/GRANULE/L1C_T16TFM_A035544_20220412T163959/IMG_DATA/T16TFM_20190412T162841_TCI.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_AOT_10m.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_B02_10m.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_B03_10m.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_B04_10m.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_B08_10m.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_TCI_10m.jp2
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20190414T110751_WVP_10m.jp2
Binary file not shown.
Binary file modified
BIN
-24 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_AOT_10m.jp2
Binary file not shown.
Binary file modified
BIN
-6 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_B02_10m.jp2
Binary file not shown.
Binary file modified
BIN
+11 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_B03_10m.jp2
Binary file not shown.
Binary file modified
BIN
+2 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_B04_10m.jp2
Binary file not shown.
Binary file modified
BIN
-7 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_B08_10m.jp2
Binary file not shown.
Binary file modified
BIN
+13 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_TCI_10m.jp2
Binary file not shown.
Binary file modified
BIN
-17 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R10m/T26EMU_20220414T110751_WVP_10m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_AOT_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B01_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B02_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B03_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.15 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B04_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B05_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.17 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B06_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.17 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B07_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.17 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B11_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B12_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.17 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_B8A_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_SCL_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_TCI_20m.jp2
Binary file not shown.
Binary file added
BIN
+4.16 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20190414T110751_WVP_20m.jp2
Binary file not shown.
Binary file modified
BIN
+10 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_AOT_20m.jp2
Binary file not shown.
Binary file modified
BIN
-1 Byte
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B01_20m.jp2
Binary file not shown.
Binary file modified
BIN
-6 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B02_20m.jp2
Binary file not shown.
Binary file modified
BIN
+8 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B03_20m.jp2
Binary file not shown.
Binary file modified
BIN
+15 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B04_20m.jp2
Binary file not shown.
Binary file modified
BIN
-4 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B05_20m.jp2
Binary file not shown.
Binary file modified
BIN
+7 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B06_20m.jp2
Binary file not shown.
Binary file modified
BIN
+3 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B07_20m.jp2
Binary file not shown.
Binary file modified
BIN
-9 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B11_20m.jp2
Binary file not shown.
Binary file modified
BIN
-7 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B12_20m.jp2
Binary file not shown.
Binary file modified
BIN
-4 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_B8A_20m.jp2
Binary file not shown.
Binary file modified
BIN
+8 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_SCL_20m.jp2
Binary file not shown.
Binary file modified
BIN
+3 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_TCI_20m.jp2
Binary file not shown.
Binary file modified
BIN
+8 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R20m/T26EMU_20220414T110751_WVP_20m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_AOT_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B01_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B02_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.6 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B03_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.6 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B04_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B05_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B06_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B07_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B09_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.6 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B11_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B12_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_B8A_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.6 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_SCL_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.6 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_TCI_60m.jp2
Binary file not shown.
Binary file added
BIN
+2.61 KB
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20190414T110751_WVP_60m.jp2
Binary file not shown.
Binary file modified
BIN
-4 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_AOT_60m.jp2
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B01_60m.jp2
Binary file not shown.
Binary file modified
BIN
+3 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B02_60m.jp2
Binary file not shown.
Binary file modified
BIN
+2 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B03_60m.jp2
Binary file not shown.
Binary file modified
BIN
-3 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B04_60m.jp2
Binary file not shown.
Binary file modified
BIN
-1 Byte
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B05_60m.jp2
Binary file not shown.
Binary file modified
BIN
+2 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B06_60m.jp2
Binary file not shown.
Binary file modified
BIN
-2 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B07_60m.jp2
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B09_60m.jp2
Binary file not shown.
Binary file modified
BIN
-3 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B11_60m.jp2
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B12_60m.jp2
Binary file not shown.
Binary file modified
BIN
+2 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_B8A_60m.jp2
Binary file not shown.
Binary file modified
BIN
-1 Byte
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_SCL_60m.jp2
Binary file not shown.
Binary file modified
BIN
+3 Bytes
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_TCI_60m.jp2
Binary file not shown.
Binary file modified
BIN
-1 Byte
(100%)
...ANULE/L2A_T26EMU_A035569_20220414T110747/IMG_DATA/R60m/T26EMU_20220414T110751_WVP_60m.jp2
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
"""Sentinel-2 and NCCM datamodule.""" | ||
|
||
from typing import Any, Optional, Union | ||
|
||
import kornia.augmentation as K | ||
import torch | ||
from kornia.constants import DataKey, Resample | ||
from matplotlib.figure import Figure | ||
|
||
from ..datasets import NCCM, Sentinel2, random_grid_cell_assignment | ||
from ..samplers import GridGeoSampler, RandomBatchGeoSampler | ||
from ..samplers.utils import _to_tuple | ||
from ..transforms import AugmentationSequential | ||
from .geo import GeoDataModule | ||
|
||
|
||
class Sentinel2NCCMDataModule(GeoDataModule): | ||
"""LightningDataModule implementation for the Sentinel-2 and NCCM dataset. | ||
.. versionadded:: 0.6 | ||
""" | ||
|
||
def __init__( | ||
self, | ||
batch_size: int = 64, | ||
patch_size: Union[int, tuple[int, int]] = 64, | ||
length: Optional[int] = None, | ||
num_workers: int = 0, | ||
**kwargs: Any, | ||
) -> None: | ||
"""Initialize a new Sentinel2NCCMDataModule instance. | ||
Args: | ||
batch_size: Size of each mini-batch. | ||
patch_size: Size of each patch, either ``size`` or ``(height, width)``. | ||
length: Length of each training epoch. | ||
num_workers: Number of workers for parallel data loading. | ||
**kwargs: Additional keyword arguments passed to | ||
:class:`~torchgeo.datasets.NCCM` (prefix keys with ``nccm_``) and | ||
:class:`~torchgeo.datasets.Sentinel2` | ||
(prefix keys with ``sentinel2_``). | ||
""" | ||
# Define prefix for NCCM and Sentinel-2 arguments | ||
nccm_signature = "nccm_" | ||
sentinel2_signature = "sentinel2_" | ||
self.nccm_kwargs = {} | ||
self.sentinel2_kwargs = {} | ||
|
||
for key, val in kwargs.items(): | ||
# Check if the current key starts with the NCCM prefix | ||
if key.startswith(nccm_signature): | ||
# If so, extract the key-value pair to the NCCM dictionary | ||
self.nccm_kwargs[key[len(nccm_signature) :]] = val | ||
# Check if the current key starts with the Sentinel-2 prefix | ||
elif key.startswith(sentinel2_signature): | ||
# If so, extract the key-value pair to the Sentinel-2 dictionary | ||
self.sentinel2_kwargs[key[len(sentinel2_signature) :]] = val | ||
|
||
super().__init__( | ||
NCCM, batch_size, patch_size, length, num_workers, **self.nccm_kwargs | ||
) | ||
|
||
self.train_aug = AugmentationSequential( | ||
K.Normalize(mean=self.mean, std=self.std), | ||
K.RandomResizedCrop(_to_tuple(self.patch_size), scale=(0.6, 1.0)), | ||
K.RandomVerticalFlip(p=0.5), | ||
K.RandomHorizontalFlip(p=0.5), | ||
data_keys=["image", "mask"], | ||
extra_args={ | ||
DataKey.MASK: {"resample": Resample.NEAREST, "align_corners": None} | ||
}, | ||
) | ||
|
||
self.aug = AugmentationSequential( | ||
K.Normalize(mean=self.mean, std=self.std), data_keys=["image", "mask"] | ||
) | ||
|
||
def setup(self, stage: str) -> None: | ||
"""Set up datasets and samplers. | ||
Args: | ||
stage: Either 'fit', 'validate', 'test', or 'predict'. | ||
""" | ||
self.sentinel2 = Sentinel2(**self.sentinel2_kwargs) | ||
self.nccm = NCCM(**self.nccm_kwargs) | ||
self.dataset = self.sentinel2 & self.nccm | ||
|
||
generator = torch.Generator().manual_seed(0) | ||
|
||
(self.train_dataset, self.val_dataset, self.test_dataset) = ( | ||
random_grid_cell_assignment( | ||
self.dataset, [0.8, 0.1, 0.1], grid_size=8, generator=generator | ||
) | ||
) | ||
if stage in ["fit"]: | ||
self.train_batch_sampler = RandomBatchGeoSampler( | ||
self.train_dataset, self.patch_size, self.batch_size, self.length | ||
) | ||
if stage in ["fit", "validate"]: | ||
self.val_sampler = GridGeoSampler( | ||
self.val_dataset, self.patch_size, self.patch_size | ||
) | ||
if stage in ["test"]: | ||
self.test_sampler = GridGeoSampler( | ||
self.test_dataset, self.patch_size, self.patch_size | ||
) | ||
|
||
def plot(self, *args: Any, **kwargs: Any) -> Figure: | ||
"""Run NCCM plot method. | ||
Args: | ||
*args: Arguments passed to plot method. | ||
**kwargs: Keyword arguments passed to plot method. | ||
Returns: | ||
A matplotlib Figure with the image, ground truth, and predictions. | ||
""" | ||
return self.nccm.plot(*args, **kwargs) |