modelio

Module to handle various IO from dataloaders and to models.

autoencoder_io(batch: dict[Any, Any], model: MinervaModel, device: device, train: bool, **kwargs) tuple[Tensor, Tensor, Tensor, Tensor | tuple[Tensor, ...], Sequence[str] | Sequence[int] | Sequence[BoundingBox] | None]

Provides IO functionality for an autoencoder using torchgeo datasets by only using the same data for input and ground truth.

Parameters:
  • batch (dict[Any, Any]) – Batch of data in a dict. Must have "image", "mask"/ "label" and "bbox" / "bounds" / "id" keys.

  • model (MinervaModel) – Model being fitted.

  • device (device) – torch device object to send data to (e.g. CUDA device).

  • train (bool) – True to run a step of the model in training mode. False for eval mode.

Keyword Arguments:
  • autoencoder_data_key (str) – Key of the data type in the sample dict to use for both input and ground truth. Must be either "mask" or "image".

  • mix_precision (bool) – Use mixed-precision. Will set the floating tensors to 16-bit rather than the default 32-bit.

Returns:

tuple[

~torch.Tensor, ~torch.Tensor, ~torch.Tensor, ~torch.Tensor | tuple[~torch.Tensor, …], ~typing.Sequence[~torchgeo.datasets.utils.BoundingBox] | None

]: The loss, the input supplied to the the model, x, the ground truth, y, the model output z, and the bounding boxes/ index of the sample supplied to the model.

Raises:

ValueError – If the value given for key is not "mask" or "image".

Added in version 0.23.

change_detection_io(batch: dict[Any, Any], model: MinervaModel, device: device, train: bool, **kwargs) tuple[Tensor, Tensor, Tensor, Tensor | tuple[Tensor, ...], Sequence[str] | Sequence[int] | Sequence[BoundingBox] | None]

Provides IO functionality for a change_detection model.

Parameters:
  • batch (dict[Any, Any]) – Batch of data in a dict. Must have "image1", "image2", "mask"/ "label" and "bbox" / "bounds" / "id" keys.

  • model (MinervaModel) – Model being fitted.

  • device (device) – torch device object to send data to (e.g. CUDA device).

  • train (bool) – True to run a step of the model in training mode. False for eval mode.

Kwargs:
mix_precision (bool): Use mixed-precision. Will set the floating tensors to 16-bit

rather than the default 32-bit.

target_key (str): Should be either "mask" or "label".

Returns:

tuple[

~torch.Tensor, ~torch.Tensor, ~torch.Tensor, ~torch.Tensor | tuple[~torch.Tensor, …], ~typing.Sequence[~torchgeo.datasets.utils.BoundingBox] | None

]: The loss, the input supplied to the the model, x, the ground truth, y, the model output z, and the bounding boxes/ index of the sample supplied to the model.

ssl_pair_torchgeo_io(batch: tuple[dict[str, Any], dict[str, Any]], model: MinervaModel, device: device, train: bool, **kwargs) tuple[Tensor, Tensor, None, Tensor | tuple[Tensor, ...], Sequence[BoundingBox] | Sequence[int] | None]

Provides IO functionality for a self-supervised Siamese model using torchgeo datasets.

Parameters:
  • batch (tuple[dict[str, Any], dict[str, Any]]) – Pair of batches of data in dict (s). Must have "image" and "bbox" / "bounds" / "id" keys.

  • model (MinervaModel) – Model being fitted.

  • device (device) – torch device object to send data to (e.g. CUDA device).

  • train (bool) – True to run a step of the model in training mode. False for eval mode.

Kwargs:
mix_precision (bool): Use mixed-precision. Will set the floating tensors to 16-bit

rather than the default 32-bit.

Returns:

tuple[

~torch.Tensor, ~torch.Tensor, None, ~torch.Tensor | tuple[~torch.Tensor, …], ~typing.Sequence[~torchgeo.datasets.utils.BoundingBox] | None

]: The loss, the input supplied to the the model, x, None (as there are no labels), the model output z, the y supplied and the bounding boxes/ index of the sample supplied to the model.

supervised_torchgeo_io(batch: dict[Any, Any], model: MinervaModel, device: device, train: bool, **kwargs) tuple[Tensor, Tensor, Tensor, Tensor | tuple[Tensor, ...], Sequence[str] | Sequence[int] | Sequence[BoundingBox] | None]

Provides IO functionality for a supervised model using torchgeo datasets.

Parameters:
  • batch (dict[Any, Any]) – Batch of data in a dict. Must have "image", "mask"/ "label" and "bbox" / "bounds" / "id" keys.

  • model (MinervaModel) – Model being fitted.

  • device (device) – torch device object to send data to (e.g. CUDA device).

  • train (bool) – True to run a step of the model in training mode. False for eval mode.

Kwargs:
mix_precision (bool): Use mixed-precision. Will set the floating tensors to 16-bit

rather than the default 32-bit.

target_key (str): Should be either "mask" or "label".

Returns:

tuple[

~torch.Tensor, ~torch.Tensor, ~torch.Tensor, ~torch.Tensor | tuple[~torch.Tensor, …], ~typing.Sequence[~torchgeo.datasets.utils.BoundingBox] | None

]: The loss, the input supplied to the the model, x, the ground truth, y, the model output z, and the bounding boxes/ index of the sample supplied to the model.