From 5d253c55d8a76d6fbd9c00e024237a247eea74f4 Mon Sep 17 00:00:00 2001 From: Jingtong <115182031+cookie-kyu@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:34:13 -0500 Subject: [PATCH] Add South America Soybean DataModule (#1959) * Add South America Soybean DataModule * Add train_aug * Regenerate data --------- Co-authored-by: Adam J. Stewart --- docs/api/datamodules.rst | 1 + .../conf/sentinel2_south_america_soybean.yaml | 17 +++ .../SouthAmericaSoybean.zip | Bin 1578 -> 7512 bytes .../South_America_Soybean_2002.tif | Bin 644 -> 3568 bytes .../South_America_Soybean_2021.tif | Bin 643 -> 3558 bytes tests/data/south_america_soybean/data.py | 13 +- tests/trainers/test_segmentation.py | 1 + torchgeo/datamodules/__init__.py | 2 + .../sentinel2_south_america_soybean.py | 123 ++++++++++++++++++ 9 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 tests/conf/sentinel2_south_america_soybean.yaml create mode 100644 torchgeo/datamodules/sentinel2_south_america_soybean.py diff --git a/docs/api/datamodules.rst b/docs/api/datamodules.rst index cb6dea18f0d..87fd8b48bf1 100644 --- a/docs/api/datamodules.rst +++ b/docs/api/datamodules.rst @@ -36,6 +36,7 @@ Sentinel .. autoclass:: Sentinel2CDLDataModule .. autoclass:: Sentinel2NCCMDataModule +.. autoclass:: Sentinel2SouthAmericaSoybeanDataModule Non-geospatial DataModules -------------------------- diff --git a/tests/conf/sentinel2_south_america_soybean.yaml b/tests/conf/sentinel2_south_america_soybean.yaml new file mode 100644 index 00000000000..1d1b91ba067 --- /dev/null +++ b/tests/conf/sentinel2_south_america_soybean.yaml @@ -0,0 +1,17 @@ +model: + class_path: SemanticSegmentationTask + init_args: + loss: "ce" + model: "deeplabv3+" + backbone: "resnet18" + in_channels: 13 + num_classes: 2 + num_filters: 1 +data: + class_path: Sentinel2SouthAmericaSoybeanDataModule + init_args: + batch_size: 2 + patch_size: 16 + dict_kwargs: + south_america_soybean_paths: "tests/data/south_america_soybean" + sentinel2_paths: "tests/data/sentinel2" diff --git a/tests/data/south_america_soybean/SouthAmericaSoybean.zip b/tests/data/south_america_soybean/SouthAmericaSoybean.zip index 5453b89fc25128d3e30c0281ee069bf1e8773aa7..630cc6c94c9fbd9d70941e3389b1721fde784224 100644 GIT binary patch literal 7512 zcmb_hWl)?;n|%o$f(F;%!QBHP!QCae%;4^Wgd{-l;2JbIgWF((27*IycXxN$-0$A4 zt=-!Fv0K|+-Tm~b>T{}pJ$34+Dj*`^1Ah&UD2VRAihnk_Kc|)}*u|CO9mv$4!_Cpf z+{zN{$l(Tdb#vtanYx*BxH`JKSs9z!gI%o6O^sb0A!cAx2M&$D(06}>8vkIb|Hz>I zOXiHZy(kM{k-1CCJlcQSAV0AKC;&hK0NyB@AQA(BAOZknN}`55 z171lX0vB>MZD0U!$Ta>VkbnTx5CgA1qX4NSPrZQn`y>CGr>(>#sRvgE3A?Awo00nm zW@!L;SmSM##VA&3bZW6IRxv|j2VN*{LB0yMc_=TTX02oP3(H5334rL*oUuXwPW3+ zMTp6Fm%iO(ynwIQ7U|z4lxLkb>u^>eiZZ*aIvV0o)5YvBvB3|~td}jS+j7ISfn`t8 zz=RK>a~mps16_@e?T}Urz0@cC0&tOl9o&!e%`B(AVT+bPvsqsHESanrXE-v;_TT;&9Ye%>t6^NCAQ}9y%91=cfy|UZ1>a7 z3)7c1*Nl@88&K8xbT|fG>4DRD*B)?dXp;xEa$FR4P+k=tgcYpb;uF%}pfyFQ0qsMN zlNoGtZHL3u?81H;=}wC*g!V!;&}vdp{HishkeVDZ6rZqTfq0&haVeoUcy)&+mT0|H z%V6>Jn`NTkr)*44W9}0&n zvrJzatgYA+H*NHG=Nj63mt$OE`UpVL>qXqS@aTCAcx>DzRMPKqcssTscjkEX>dI{v zfwyrQ-bU=w-1rlLJs8O#88$)82!Yf2cao1U>cP@tkxlD6;&#X}KO(4fRKBtf42tYy z_A->VWeH`bm-r7M+r2b%%NM2eG9TLO<^v&*K4j9JO@EE{_o53 z#(8hoXv<>4t&YOlk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$*GyH}j>4KHHnv2gBHLt_b8kT6|UAX50Yz*5SiOWLAe!2BzwI zoMOm~=wP{qE=^j|5S4CfYQo%+ZEIJMVbPw@qrqgoiZxZLzx$~bHT0=$N#(_Xmg>+3 zDwiTz8Eb!T0)7_Om-EcdibvkH$zKgC;t*{&E&ZXadLFYtgz1Ns`HmSE`cy5II8_Iz zj3+<-T*~L>F!3_$kYt(>*|si42W_5J*M-7i65JZq$1!hCA>aaj@Gx z`9iykJz_tWWwOqwnuB*ojfxJZo>5v*zphKJ`LN9}6Y^_q-P3RC*Ty^<5o%-Hf_WF$ zog0{_Pcg|_#3VNxe45V_Hf0SYpwP*T;HZebAScM<&nE#Rlmc5hzQ}~MfnjGE&z%(! zmRBi-)^cqm=T{Q_i7!xw!luvi&izEH(3$eIA{n`UkDdQjWVzkYFa!M*K0*GCQWFsq jTyz)d=8mB}=kBSXlPZ~+iGywZ&`}3%k;;)WQo#QM1ur!{ delta 437 zcmew$-NGvG>8ZuQ!N9;E$iTqJ%)kg_DF87ej6G3an++sb#W*oQj1MFw&d35*#>F_X zM9b)UjEG+r>{2c zgjPvq?4!$>n}gO}k6!Ax(|&Ep2GJSYj7}P^Nd6Su!?Wyo{R;0FraQl$`x$oP^k(xF zXPbFvZhERZ({oR&Ub5V!`>Lfg-P}6YolX6=OUtLa)@@P#XX)3nd?$-{T{6BcXToK? n;(XMPQ17Wx=ldUCO#Apd&%FNZ(l%PtwtX%7Fc0m9DTg;a- diff --git a/tests/data/south_america_soybean/SouthAmericaSoybean/South_America_Soybean_2021.tif b/tests/data/south_america_soybean/SouthAmericaSoybean/South_America_Soybean_2021.tif index a220b500677c0b2b954c9a735358450535cfec60..7aab8f3db6589e702cfb3e9aafe793c2e46e2a67 100644 GIT binary patch literal 3558 zcmZvdc{r5q`^JX|SrQ>T2^l74#%{FqbYZ{OqSkKcV9=W%|X^S-Y8d7kT^+t3gQU<3dF>;M4G82}BH9#KW} z2h;xMUsY#*Gd-2h{^nmj7ij1Jv{av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2YJhCoP zWU>3BASsz!=H`=5s+P?Bqt_WT_ma{kt0{d8!+}h^QE)^ diff --git a/tests/data/south_america_soybean/data.py b/tests/data/south_america_soybean/data.py index fbe7d7b23d1..63e93ebdc1d 100644 --- a/tests/data/south_america_soybean/data.py +++ b/tests/data/south_america_soybean/data.py @@ -11,7 +11,7 @@ from rasterio.crs import CRS from rasterio.transform import Affine -SIZE = 32 +SIZE = 128 np.random.seed(0) @@ -24,15 +24,8 @@ def create_file(path: str, dtype: str): "driver": "GTiff", "dtype": dtype, "count": 1, - "crs": CRS.from_epsg(4326), - "transform": Affine( - 0.0002499999999999943131, - 0.0, - -82.0005000000000024, - 0.0, - -0.0002499999999999943131, - 0.0005000000000000, - ), + "crs": CRS.from_epsg(32616), + "transform": Affine(10, 0.0, 399960.0, 0.0, -10, 4500000.0), "height": SIZE, "width": SIZE, "compress": "lzw", diff --git a/tests/trainers/test_segmentation.py b/tests/trainers/test_segmentation.py index 59c7c16cff5..40da4efead6 100644 --- a/tests/trainers/test_segmentation.py +++ b/tests/trainers/test_segmentation.py @@ -75,6 +75,7 @@ class TestSemanticSegmentationTask: "sen12ms_s2_reduced", "sentinel2_cdl", "sentinel2_nccm", + "sentinel2_south_america_soybean", "spacenet1", "ssl4eo_l_benchmark_cdl", "ssl4eo_l_benchmark_nlcd", diff --git a/torchgeo/datamodules/__init__.py b/torchgeo/datamodules/__init__.py index 1c268bb807c..a2d3eb1a666 100644 --- a/torchgeo/datamodules/__init__.py +++ b/torchgeo/datamodules/__init__.py @@ -31,6 +31,7 @@ from .sen12ms import SEN12MSDataModule from .sentinel2_cdl import Sentinel2CDLDataModule from .sentinel2_nccm import Sentinel2NCCMDataModule +from .sentinel2_south_america_soybean import Sentinel2SouthAmericaSoybeanDataModule from .skippd import SKIPPDDataModule from .so2sat import So2SatDataModule from .spacenet import SpaceNet1DataModule @@ -53,6 +54,7 @@ "NAIPChesapeakeDataModule", "Sentinel2CDLDataModule", "Sentinel2NCCMDataModule", + "Sentinel2SouthAmericaSoybeanDataModule", # NonGeoDataset "BigEarthNetDataModule", "ChaBuDDataModule", diff --git a/torchgeo/datamodules/sentinel2_south_america_soybean.py b/torchgeo/datamodules/sentinel2_south_america_soybean.py new file mode 100644 index 00000000000..6ce54000cbc --- /dev/null +++ b/torchgeo/datamodules/sentinel2_south_america_soybean.py @@ -0,0 +1,123 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + + +"""South America Soybean 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 Sentinel2, SouthAmericaSoybean, random_grid_cell_assignment +from ..samplers import GridGeoSampler, RandomBatchGeoSampler +from ..samplers.utils import _to_tuple +from ..transforms import AugmentationSequential +from .geo import GeoDataModule + + +class Sentinel2SouthAmericaSoybeanDataModule(GeoDataModule): + """LightningDataModule for SouthAmericaSoybean and Sentinel2 datasets. + + .. 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 Sentinel2SouthAmericaSoybeanDataModule 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.SouthAmericaSoybean` + (prefix keys with ``south_america_soybean_``) and + :class:`~torchgeo.datasets.Sentinel2` + (prefix keys with ``sentinel2_``). + """ + self.south_america_soybean_kwargs = {} + self.sentinel2_kwargs = {} + for key, val in kwargs.items(): + if key.startswith("south_america_soybean_"): + self.south_america_soybean_kwargs[key[22:]] = val + elif key.startswith("sentinel2_"): + self.sentinel2_kwargs[key[10:]] = val + + super().__init__( + SouthAmericaSoybean, + batch_size=batch_size, + patch_size=patch_size, + length=length, + num_workers=num_workers, + **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.south_america_soybean = SouthAmericaSoybean( + **self.south_america_soybean_kwargs + ) + self.dataset = self.sentinel2 & self.south_america_soybean + + generator = torch.Generator().manual_seed(1) + (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 SouthAmericaSoybean 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.south_america_soybean.plot(*args, **kwargs)