Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomGeoSampler for Pre-chipped Datasets #1976

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions torchgeo/datamodules/agrifieldnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from kornia.constants import DataKey, Resample

from ..datasets import AgriFieldNet, random_bbox_assignment
from ..samplers import GridGeoSampler, RandomBatchGeoSampler
from ..samplers import GridGeoSampler, RandomGeoSampler
from ..samplers.utils import _to_tuple
from ..transforms import AugmentationSequential
from .geo import GeoDataModule
Expand Down Expand Up @@ -73,8 +73,8 @@ def setup(self, stage: str) -> None:
)

if stage in ["fit"]:
self.train_batch_sampler = RandomBatchGeoSampler(
self.train_dataset, self.patch_size, self.batch_size, self.length
self.train_sampler = RandomGeoSampler(
self.train_dataset, self.patch_size, self.length
)
if stage in ["fit", "validate"]:
self.val_sampler = GridGeoSampler(
Expand Down
12 changes: 5 additions & 7 deletions torchgeo/datamodules/sentinel2_cdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from kornia.constants import DataKey, Resample
from matplotlib.figure import Figure

from ..datasets import CDL, Sentinel2, random_grid_cell_assignment
from ..samplers import GridGeoSampler, RandomBatchGeoSampler
from ..datasets import CDL, Sentinel2, random_bbox_assignment
from ..samplers import GridGeoSampler, RandomGeoSampler
from ..samplers.utils import _to_tuple
from ..transforms import AugmentationSequential
from .geo import GeoDataModule
Expand Down Expand Up @@ -91,13 +91,11 @@ def setup(self, stage: str) -> None:
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
)
random_bbox_assignment(self.dataset, [0.8, 0.1, 0.1], generator=generator)
)
if stage in ["fit"]:
self.train_batch_sampler = RandomBatchGeoSampler(
self.train_dataset, self.patch_size, self.batch_size, self.length
self.train_sampler = RandomGeoSampler(
self.train_dataset, self.patch_size, self.length
)
if stage in ["fit", "validate"]:
self.val_sampler = GridGeoSampler(
Expand Down
12 changes: 5 additions & 7 deletions torchgeo/datamodules/sentinel2_eurocrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from kornia.constants import DataKey, Resample
from matplotlib.figure import Figure

from ..datasets import EuroCrops, Sentinel2, random_grid_cell_assignment
from ..samplers import GridGeoSampler, RandomBatchGeoSampler
from ..datasets import EuroCrops, Sentinel2, random_bbox_assignment
from ..samplers import GridGeoSampler, RandomGeoSampler
from ..samplers.utils import _to_tuple
from ..transforms import AugmentationSequential
from .geo import GeoDataModule
Expand Down Expand Up @@ -91,13 +91,11 @@ def setup(self, stage: str) -> None:

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
)
random_bbox_assignment(self.dataset, [0.8, 0.1, 0.1], generator=generator)
)
if stage in ["fit"]:
self.train_batch_sampler = RandomBatchGeoSampler(
self.train_dataset, self.patch_size, self.batch_size, self.length
self.train_sampler = RandomGeoSampler(
self.train_dataset, self.patch_size, self.length
)
if stage in ["fit", "validate"]:
self.val_sampler = GridGeoSampler(
Expand Down
12 changes: 5 additions & 7 deletions torchgeo/datamodules/sentinel2_nccm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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 ..datasets import NCCM, Sentinel2, random_bbox_assignment
from ..samplers import GridGeoSampler, RandomGeoSampler
from ..samplers.utils import _to_tuple
from ..transforms import AugmentationSequential
from .geo import GeoDataModule
Expand Down Expand Up @@ -91,13 +91,11 @@ def setup(self, stage: str) -> None:
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
)
random_bbox_assignment(self.dataset, [0.8, 0.1, 0.1], generator=generator)
)
if stage in ["fit"]:
self.train_batch_sampler = RandomBatchGeoSampler(
self.train_dataset, self.patch_size, self.batch_size, self.length
self.train_sampler = RandomGeoSampler(
self.train_dataset, self.patch_size, self.length
)
if stage in ["fit", "validate"]:
self.val_sampler = GridGeoSampler(
Expand Down
12 changes: 5 additions & 7 deletions torchgeo/datamodules/sentinel2_south_america_soybean.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
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 ..datasets import Sentinel2, SouthAmericaSoybean, random_bbox_assignment
from ..samplers import GridGeoSampler, RandomGeoSampler
from ..samplers.utils import _to_tuple
from ..transforms import AugmentationSequential
from .geo import GeoDataModule
Expand Down Expand Up @@ -91,14 +91,12 @@ def setup(self, stage: str) -> None:

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
)
random_bbox_assignment(self.dataset, [0.8, 0.1, 0.1], generator=generator)
)

if stage in ["fit"]:
self.train_batch_sampler = RandomBatchGeoSampler(
self.train_dataset, self.patch_size, self.batch_size, self.length
self.train_sampler = RandomGeoSampler(
self.train_dataset, self.patch_size, self.length
)
if stage in ["fit", "validate"]:
self.val_sampler = GridGeoSampler(
Expand Down
Loading