Threshold

class hybrid_learning.datasets.transforms.image_transforms.Threshold(threshold=0.5, val_low_class=0.0, val_high_class=1.0)[source]

Bases: ImageTransform

Threshold tensors and set new values below and/or above the threshold. The operation is:

Each of the thresholds val_low_class and val_high_class can also be set to None, in which case``x`` is used instead. Set values to both to obtain a binarizing operation.

Note

val_low_class needs not to be lower than val_high_class, so one can also invert binary masks with this.

Public Data Attributes:

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(input_tensor)

Binarize input_tensor according to the settings.

Inherited from : py: class:ImageTransform

apply_to(input_tensor)

Binarize input_tensor according to the settings.

Inherited from : py: class:Transform

apply_to(input_tensor)

Binarize input_tensor according to the settings.

Special Methods:

__init__([threshold, val_low_class, ...])

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__(threshold=0.5, val_low_class=0.0, val_high_class=1.0)[source]

Init.

Parameters
apply_to(input_tensor)[source]

Binarize input_tensor according to the settings. In case any of this instances settings are tensors, these are moved to the same device as input_tensor.

Parameters

input_tensor (Tensor) –

Return type

Tensor

property settings: Dict[str, Any]

Settings to reproduce instance.

threshold: Union[float, Tensor]

Threshold by which to decide the class; low class if x<=post_target_thresh, else high

val_high_class: Optional[Union[float, Tensor]]

Value to set the high class to. If set to None, the input value is used.

val_low_class: Optional[Union[float, Tensor]]

Value to set the low class to. If set to None, the input value is used.