Shortcuts

Source code for torchgeo.datamodules.gid15

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

"""GID-15 datamodule."""

from typing import Any

import kornia.augmentation as K

from ..datasets import GID15
from ..samplers.utils import _to_tuple
from ..transforms import AugmentationSequential
from ..transforms.transforms import _RandomNCrop
from .geo import NonGeoDataModule
from .utils import dataset_split


[docs]class GID15DataModule(NonGeoDataModule): """LightningDataModule implementation for the GID-15 dataset. Uses the train/test splits from the dataset. .. versionadded:: 0.4 """
[docs] def __init__( self, batch_size: int = 64, patch_size: tuple[int, int] | int = 64, val_split_pct: float = 0.2, num_workers: int = 0, **kwargs: Any, ) -> None: """Initialize a new GID15DataModule instance. Args: batch_size: Size of each mini-batch. patch_size: Size of each patch, either ``size`` or ``(height, width)``. Should be a multiple of 32 for most segmentation architectures. val_split_pct: Percentage of the dataset to use as a validation set num_workers: Number of workers for parallel data loading. **kwargs: Additional keyword arguments passed to :class:`~torchgeo.datasets.GID15`. """ super().__init__(GID15, 1, num_workers, **kwargs) self.patch_size = _to_tuple(patch_size) self.val_split_pct = val_split_pct self.train_aug = self.val_aug = AugmentationSequential( K.Normalize(mean=self.mean, std=self.std), _RandomNCrop(self.patch_size, batch_size), data_keys=["image", "mask"], ) self.predict_aug = AugmentationSequential( K.Normalize(mean=self.mean, std=self.std), _RandomNCrop(self.patch_size, batch_size), data_keys=["image"], )
[docs] def setup(self, stage: str) -> None: """Set up datasets. Args: stage: Either 'fit', 'validate', 'test', or 'predict'. """ if stage in ["fit", "validate"]: self.dataset = GID15(split="train", **self.kwargs) self.train_dataset, self.val_dataset = dataset_split( self.dataset, self.val_split_pct ) if stage in ["test"]: # Test set masks are not public, use for prediction instead self.predict_dataset = GID15(split="test", **self.kwargs)

© Copyright 2021, Microsoft Corporation. Revision acad7d47.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
v0.5.2
v0.5.1
v0.5.0
v0.4.1
v0.4.0
v0.3.1
v0.3.0
v0.2.1
v0.2.0
v0.1.1
v0.1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources