BatchIoUEncode2D
- class hybrid_learning.datasets.transforms.encoder.BatchIoUEncode2D(proto_shape=None, kernel_size=None, smooth=1e-07)[source]
Bases:
BatchConvOp
Apply intersection over union encoding to an input batch. The batch is assumed to be of shape
(batch_size, 1, height, width).
Idea
The idea of intersection over union (IoU) encoding is to have a generalized and continuous bounding box score. The better a given proto-shape (e.g. a box) overlaps with the ground truth shape, the higher the value in
[0,1]
. More precisely, in an IoU encoding of a segmentation target, a pixel holds the IoU value of the actual segmentation with a pre-defined proto-shape centered at this pixel. In a traditional segmentation a pixel holds the information whether it is part of a visual object in the image.Such a proto shape is defined by a (not necessarily binary) mask, which may be at most the size of the target mask.
Theoretical Notes
Since the pixel values of proto shape and segmentation mask need not be binary, they are treated as fuzzy sets. Intersection and union of masks are calculated with respect to the product t-norm (see
BatchIntersectEncode2D
). The area values are collected by reduction by sum.Implementation Notes
To change from 2D to other image dimensionality, replace the padding and pooling layer and adapt
AREA_DIMS
accordingly.Public Data Attributes:
The proto shape used for IoU calculation
Settings to reproduce instance.
Inherited from : py: class:BatchConvOp
The proto shape used for IoU calculation
kernel_size
The kernel size of the proto-type shape.
Settings to reproduce instance.
Inherited from : py: class:BatchWindowOp
AREA_DIMS
Indices of axes in which the image area is defined.
kernel_size
The kernel size of the proto-type shape.
Settings to reproduce instance.
Public Methods:
smooth_division
(dividend, divisor)Smoothed division using smoothening summand to avoid division by 0.
conv_op
(masks)Encode given masks as IoU masks.
Inherited from : py: class:BatchWindowOp
forward
(masks)Wrapper for the convolutional operation on batch of masks.
conv_op
(masks)Encode given masks as IoU masks.
Inherited from : py: class:Module
forward
(masks)Wrapper for the convolutional operation on batch of masks.
register_buffer
(name, tensor[, persistent])Adds a buffer to the module.
register_parameter
(name, param)Adds a parameter to the module.
add_module
(name, module)Adds a child module to the current module.
get_submodule
(target)Returns the submodule given by
target
if it exists, otherwise throws an error.get_parameter
(target)Returns the parameter given by
target
if it exists, otherwise throws an error.get_buffer
(target)Returns the buffer given by
target
if it exists, otherwise throws an error.apply
(fn)Applies
fn
recursively to every submodule (as returned by.children()
) as well as self.cuda
([device])Moves all model parameters and buffers to the GPU.
xpu
([device])Moves all model parameters and buffers to the XPU.
cpu
()Moves all model parameters and buffers to the CPU.
type
(dst_type)Casts all parameters and buffers to
dst_type
.float
()Casts all floating point parameters and buffers to
float
datatype.double
()Casts all floating point parameters and buffers to
double
datatype.half
()Casts all floating point parameters and buffers to
half
datatype.bfloat16
()Casts all floating point parameters and buffers to
bfloat16
datatype.to_empty
(*, device)Moves the parameters and buffers to the specified device without copying storage.
to
(*args, **kwargs)Moves and/or casts the parameters and buffers.
register_backward_hook
(hook)Registers a backward hook on the module.
register_full_backward_hook
(hook)Registers a backward hook on the module.
register_forward_pre_hook
(hook)Registers a forward pre-hook on the module.
register_forward_hook
(hook)Registers a forward hook on the module.
state_dict
([destination, prefix, keep_vars])Returns a dictionary containing a whole state of the module.
load_state_dict
(state_dict[, strict])Copies parameters and buffers from
state_dict
into this module and its descendants.parameters
([recurse])Returns an iterator over module parameters.
named_parameters
([prefix, recurse])Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
buffers
([recurse])Returns an iterator over module buffers.
named_buffers
([prefix, recurse])Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
children
()Returns an iterator over immediate children modules.
named_children
()Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
modules
()Returns an iterator over all modules in the network.
named_modules
([memo, prefix, remove_duplicate])Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
train
([mode])Sets the module in training mode.
eval
()Sets the module in evaluation mode.
requires_grad_
([requires_grad])Change if autograd should record operations on parameters in this module.
zero_grad
([set_to_none])Sets gradients of all model parameters to zero.
share_memory
()extra_repr
()Set the extra representation of the module
Special Methods:
__init__
([proto_shape, kernel_size, smooth])Init.
Inherited from : py: class:BatchWindowOp
__repr__
()Representation based on this instances settings.
Inherited from : py: class:Module
__init__
([proto_shape, kernel_size, smooth])Init.
__call__
(*input, **kwargs)Call self as a function.
__setstate__
(state)__getattr__
(name)__setattr__
(name, value)Implement setattr(self, name, value).
__delattr__
(name)Implement delattr(self, name).
__repr__
()Representation based on this instances settings.
__dir__
()Default dir() implementation.
- conv_op(masks)[source]
Encode given masks as IoU masks.
- Parameters
masks (Tensor) –
torch.Tensor
of shape(batch_size, 1, width, height)
holding the segmentation masks for one batch- Returns
torch.Tensor
of the same size as masks tensor holding IoU encoding of the latter- Return type
- smooth_division(dividend, divisor)[source]
Smoothed division using smoothening summand to avoid division by 0.
- Returns
result of smooth division.
- property proto_shape: numpy.ndarray
The proto shape used for IoU calculation