mlreco.models.layers.common.blocks module

class mlreco.models.layers.common.blocks.Identity[source]

Bases: torch.nn.modules.module.Module

__init__()[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(input)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

__module__ = 'mlreco.models.layers.common.blocks'
training: bool
mlreco.models.layers.common.blocks.dense_coordinates(shape: Union[list, torch.Size])[source]

coordinates = dense_coordinates(tensor.shape)

mlreco.models.layers.common.blocks.to_sparse(dense_tensor: torch.Tensor, resolution: int, coordinates: Optional[torch.Tensor] = None, coords_key=None, coords_man=None)[source]

Converts a (differentiable) dense tensor to a sparse tensor. Assume the input to have BxCxD1xD2x….xDN format. If the shape of the tensor do not change, use dense_coordinates to cache the coordinates. Please refer to tests/python/dense.py for usage Example:

>>> dense_tensor = torch.rand(3, 4, 5, 6, 7, 8)  # BxCxD1xD2xD3xD4
>>> dense_tensor.requires_grad = True
>>> stensor = to_sparse(dense_tensor)
class mlreco.models.layers.common.blocks.SparseToDense[source]

Bases: torch.nn.modules.module.Module

__init__()[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(x: MinkowskiEngine.SparseTensor)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

__module__ = 'mlreco.models.layers.common.blocks'
training: bool
class mlreco.models.layers.common.blocks.DenseResBlock(in_channels, out_channels)[source]

Bases: torch.nn.modules.module.Module

__init__(in_channels, out_channels)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

__module__ = 'mlreco.models.layers.common.blocks'
training: bool
mlreco.models.layers.common.blocks.normalize_coords(coords, spatial_size=512)[source]

Utility Method for attaching normalized coordinates to sparse tensor features.

INPUTS:
  • input (scn.SparseConvNetTensor): sparse tensor to

attach normalized coordinates with range (-1, 1)

Returns

sparse tensor with normalized coordinate concatenated to first three dimensions.

Return type

  • output (scn.SparseConvNetTensor)

class mlreco.models.layers.common.blocks.ConvolutionBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

__init__(in_features, out_features, stride=1, dilation=1, dimension=3, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={}, has_bias=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.DropoutBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

__init__(in_features, out_features, stride=1, dilation=1, dimension=3, p=0.5, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={}, bias=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.ResNetBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

ResNet Block with Leaky ReLU nonlinearities.

expansion = 1
__init__(in_features, out_features, stride=1, dilation=1, dimension=3, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={}, bias=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.AtrousIIBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

ResNet-type block with Atrous Convolutions, as developed in ACNN paper: <ACNN: a Full Resolution DCNN for Medical Image Segmentation> Original Paper: https://arxiv.org/pdf/1901.09203.pdf

__init__(in_features, out_features, dimension=3, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={})[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.ResNeXtBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

ResNeXt block with leaky relu nonlinearities and atrous convs.

  • in_features (int): total number of input features

  • out_features (int): total number of output features NOTE: if in_features != out_features, then the identity skip connection is replaced with a 1x1 conv layer.

  • dimension (int): dimension of dataset.

  • leakiness (float): leakiness for LeakyReLUs.

  • cardinality (int): number of different paths, see ResNeXt paper.

  • depth (int): number of convolutions + BN + LeakyReLU layers inside

each cardinal path.

  • dilations (int or list of ints): dilation rates for atrous

convolutions.

  • kernel_sizes (int or list of ints): kernel sizes for each conv layers

inside cardinal paths.

  • strides (int or list of ints): strides for each conv layers inside

cardinal paths.

NOTE: For vanilla resnext blocks, set dilation=1 and others to default.

__init__(in_features, out_features, dimension=3, cardinality=4, depth=1, dilations=None, kernel_sizes=3, strides=1, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={})[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.SPP(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

Spatial Pyramid Pooling Module. PSPNet (Pyramid Scene Parsing Network) uses vanilla SPPs, while DeeplabV3 and DeeplabV3+ uses ASPP (atrous versions).

Default parameters will construct a global average pooling + unpooling layer which is done in ParseNet.

  • in_features (int): number of input features

  • out_features (int): number of output features

  • D (int): dimension of dataset.

  • mode (str): pooling mode. In MinkowskiEngine, currently

‘avg’, ‘max’, and ‘sum’ are supported.

  • dilations (int or list of ints): dilation rates for atrous

convolutions.

  • kernel_sizes (int or list of ints): kernel sizes for each

pooling operation. Note that kernel_size == stride for the SPP layer.

__init__(in_features, out_features, kernel_sizes=None, dilations=None, mode='avg', D=3)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(input)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.CascadeDilationBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

Cascaded Atrous Convolution Block

__init__(in_features, out_features, dimension=3, depth=6, dilations=[1, 2, 4, 8, 16, 32], activation='relu', activation_args={})[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.ASPP(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

Atrous Spatial Pyramid Pooling Module

__init__(in_features, out_features, dimension=3, width=5, dilations=[2, 4, 6, 8, 12])[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.MBConv(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

__init__(in_features, out_features, expand_ratio=2, dimension=3, dilation=1, kernel_size=3, stride=1, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={}, has_bias=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.MBResConv(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

__init__(in_features, out_features, expand_ratio=2, dimension=3, dilation=1, kernel_size=3, stride=1, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={}, has_bias=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.SEBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

Squeeze and Excitation Blocks

__init__(channels, ratio=8, dimension=3)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
class mlreco.models.layers.common.blocks.SEResNetBlock(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

Squeeze and Excitation ResNet Block with Leaky ReLU nonlinearities.

__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
expansion = 1
__init__(in_features, out_features, se_ratio=8, stride=1, dilation=1, dimension=3, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={})[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]
class mlreco.models.layers.common.blocks.MBResConvSE(*args: Any, **kwargs: Any)[source]

Bases: MinkowskiEngine.

__module__ = 'mlreco.models.layers.common.blocks'
__orig_bases__ = (MinkowskiEngine.MinkowskiNetwork,)
__init__(in_features, out_features, se_ratio=8, expand_ratio=2, dimension=3, dilation=1, kernel_size=3, stride=1, activation='relu', activation_args={}, normalization='batch_norm', normalization_args={}, has_bias=False)[source]

Initialize self. See help(type(self)) for accurate signature.

forward(x)[source]