WithThresh

class hybrid_learning.datasets.transforms.image_transforms.WithThresh(trafo, pre_thresh=None, post_thresh=None, batch_wise=False, pre_low_class=0.0, pre_high_class=1.0, post_low_class=0.0, post_high_class=1.0)[source]

Bases: BatchWiseImageTransform

Wrap a batch transformation with binarizing (and unsqueezing) before and after.

The transformation should accept a tensor holding a masks (respectively a batch of masks if batch_wise is True) and return a transformed batch. If given, pre_thresh is applied before, and post_thresh after the transformation. The transformation is assumed to require a batch of masks, so if batch_wise is False, the missing batch dimension is handled. Thus, this wrapper can also be used to turn a batch operation into one on single masks.

Public Data Attributes:

settings

Settings to reproduce instance.

Inherited from : py: class:BatchWiseImageTransform

settings

Settings to reproduce instance.

Inherited from : py: class:Transform

IDENTITY_CLASS

The identity class or classes for composition / addition.

settings

Settings to reproduce instance.

Public Methods:

apply_to_batch(masks)

Forward method in which to apply the trafo and thresholding.

Inherited from : py: class:BatchWiseImageTransform

apply_to(mask)

Apply trafo to the mask (either considered as batch of mask or single mask).

apply_to_batch(masks)

Forward method in which to apply the trafo and thresholding.

Inherited from : py: class:ImageTransform

apply_to(mask)

Apply trafo to the mask (either considered as batch of mask or single mask).

Inherited from : py: class:Transform

apply_to(mask)

Apply trafo to the mask (either considered as batch of mask or single mask).

Special Methods:

__init__(trafo[, pre_thresh, post_thresh, ...])

Init.

Inherited from : py: class:BatchWiseImageTransform

__init__(trafo[, pre_thresh, post_thresh, ...])

Init.

Inherited from : py: class:ImageTransform

__call__(img)

Application of transformation.

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__(img)

Application of transformation.


Parameters
__init__(trafo, pre_thresh=None, post_thresh=None, batch_wise=False, pre_low_class=0.0, pre_high_class=1.0, post_low_class=0.0, post_high_class=1.0)[source]

Init.

Parameters
  • trafo (Callable[[Tensor], Tensor]) – the transformation instance to wrap

  • pre_thresh (Optional[float]) – if not None, the tensors to be modified are binarized to 0 and 1 values with threshold pre_thresh before modification

  • post_thresh (Optional[float]) – if not None, the tensors to be modified are binarized to 0 and 1 values with threshold post_thresh after modification

  • batch_wise (bool) – see batch_wise

  • pre_high_class (float) – value to set items to that exceed pre_thresh

  • pre_low_class (float) – value to set items to that are below pre_thresh

  • post_high_class (float) – value to set items to that exceed post_thresh

  • post_low_class (float) – value to set items to that are below post_thresh

apply_to_batch(masks)[source]

Forward method in which to apply the trafo and thresholding.

Pre-threshold, modify, and post-threshold given mask(s). The thresholding is applied, if the corresponding pre_thresholder / post_thresholder is not None. If batch_wise is False, it is assumed a single mask was given (no batch dimension).

Parameters

masks (Tensor) – torch.Tensor of shape ([batch_size,] 1, width, height) holding masks for one batch.

Returns

the modified and thresholded masks

Return type

Tensor

batch_wise: bool

Whether to assume a batch of masks is given (True) or a single mask (False).

post_thresholder: Optional[Binarize]

Binarizing transformation applied to targets after IoU encoding if not None.

pre_thresholder: Optional[Binarize]

Binarizing transformation applied to targets before IoU encoding if not None.

property settings: Dict[str, Any]

Settings to reproduce instance.

trafo: Callable[[Tensor], Tensor]

Modifier (en- or decoder) module that is used for modifications.