SameSize

class hybrid_learning.datasets.transforms.tuple_transforms.SameSize(interpolation='bilinear', resize_target=False, only_two_tuples=None, resize_to_index=None)[source]

Bases: TupleTransforms

Given a tuple of input and target image, resize the target to the size of the input. Both input and target image must be given as torch.Tensor.

Since the center points of pixels are considered, upscaling may lead to edge pixel values that exceed the previous maximum values. Thus, make sure to clamp the output in case e.g. sigmoid output is considered:

>>> from hybrid_learning.datasets.transforms import Lambda, SameSize
>>> (SameSize(resize_target=False)
...  + OnInput(Lambda(lambda t: t.clamp(0, 1))))
Compose(transforms=[SameSize(...), OnInput(trafo=Lambda(...))])

Public Data Attributes:

settings

Settings to reproduce the instance.

Inherited from : py: class:Transform

IDENTITY_CLASS

The identity class or classes for composition / addition.

settings

Settings to reproduce the instance.

Public Methods:

apply_to(*masks)

Application of size adaptation.

Inherited from : py: class:TupleTransforms

apply_to(*masks)

Application of size adaptation.

Inherited from : py: class:Transform

apply_to(*masks)

Application of size adaptation.

Special Methods:

__init__([interpolation, resize_target, ...])

Init.

Inherited from : py: class:TupleTransforms

__init__([interpolation, resize_target, ...])

Init.

__call__(*inputs)

Apply the transformation to the tuple (inp, target); the output again is a tuple.

Inherited from : py: class:Transform

__repr__()

Return repr(self).

__eq__(other)

Return self==value.

__copy__()

Return a shallow copy of self using settings.

__add__(other)

Return a flat composition of self with other.

__radd__(other)

Return a flat composition of other and self.

__call__(*inputs)

Apply the transformation to the tuple (inp, target); the output again is a tuple.


Parameters
  • resize_target (bool) –

  • only_two_tuples (bool) –

  • resize_to_index (int) –

__init__(interpolation='bilinear', resize_target=False, only_two_tuples=None, resize_to_index=None)[source]

Init.

Note

Mind that other interpolation methods than 'nearest' will produce non-binary outputs.

Parameters
  • resize_target (bool) – if set to true, shortcut for resize_to_index=0, only_two_tuples=True, else provides default resize_to_index=-1, only_two_tuples=False

  • only_two_tuples (Optional[bool]) – check that only two-tuples are provided

  • resize_to_index (Optional[int]) – the index of a mask to which to resize; see also resize_target

  • interpolation – the interpolation method to use, parameter to torch.nn.Upsample;

apply_to(*masks)[source]

Application of size adaptation.

Parameters

masks (Tensor) –

only_two_tuples: bool

If True check that only two-tuples of masks are given.

resize_to_index: int

Resize all other masks to the mask at this index.

property settings: Dict[str, Any]

Settings to reproduce the instance.