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:
BatchWiseImageTransformWrap 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_wiseisTrue) and return a transformed batch. If given,pre_threshis applied before, andpost_threshafter the transformation. The transformation is assumed to require a batch of masks, so ifbatch_wiseisFalse, 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 to reproduce instance.
Inherited from : py: class:BatchWiseImageTransform
Settings to reproduce instance.
Inherited from : py: class:Transform
IDENTITY_CLASSThe identity class or classes for composition / addition.
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
selfwithother.__radd__(other)Return a flat composition of
otherandself.__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 thresholdpre_threshbefore modificationpost_thresh (Optional[float]) – if not
None, the tensors to be modified are binarized to 0 and 1 values with thresholdpost_threshafter modificationbatch_wise (bool) – see
batch_wisepre_high_class (float) – value to set items to that exceed
pre_threshpre_low_class (float) – value to set items to that are below
pre_threshpost_high_class (float) – value to set items to that exceed
post_threshpost_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_thresholderis notNone. Ifbatch_wiseisFalse, it is assumed a single mask was given (no batch dimension).- Parameters
masks (Tensor) –
torch.Tensorof shape([batch_size,] 1, width, height)holding masks for one batch.- Returns
the modified and thresholded masks
- Return type
- post_thresholder: Optional[Binarize]
Binarizing transformation applied to targets after IoU encoding if not
None.