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
isTrue
) and return a transformed batch. If given,pre_thresh
is applied before, andpost_thresh
after the transformation. The transformation is assumed to require a batch of masks, so ifbatch_wise
isFalse
, 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_CLASS
The 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
self
withother
.__radd__
(other)Return a flat composition of
other
andself
.__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_thresh
before modificationpost_thresh (Optional[float]) – if not
None
, the tensors to be modified are binarized to 0 and 1 values with thresholdpost_thresh
after modificationbatch_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 notNone
. Ifbatch_wise
isFalse
, 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
- post_thresholder: Optional[Binarize]
Binarizing transformation applied to targets after IoU encoding if not
None
.