MBConv3D#
- pydantic model vision_architectures.blocks.mbconv_3d.MBConv3DConfig[source]#
Bases:
CNNBlockConfig
Show JSON schema
{ "title": "MBConv3DConfig", "type": "object", "properties": { "in_channels": { "default": null, "description": "Use dim instead", "title": "In Channels", "type": "null" }, "out_channels": { "default": null, "description": "Use expansion_ratio instead", "title": "Out Channels", "type": "null" }, "kernel_size": { "default": 3, "description": "Kernel size for the convolutional layers.", "title": "Kernel Size", "type": "integer" }, "padding": { "anyOf": [ { "type": "integer" }, { "items": { "type": "integer" }, "type": "array" }, { "type": "string" } ], "default": "same", "description": "Padding for the convolution. Can be 'same' or an integer/tuple of integers.", "title": "Padding" }, "stride": { "default": 1, "description": "Stride for the convolution", "title": "Stride", "type": "integer" }, "conv_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the convolution layer", "title": "Conv Kwargs", "type": "object" }, "transposed": { "default": false, "description": "Whether to perform ConvTranspose instead of Conv", "title": "Transposed", "type": "boolean" }, "normalization": { "default": "batchnorm3d", "description": "Normalization layer to use in the block.", "title": "Normalization", "type": "string" }, "normalization_pre_args": { "default": [], "description": "Arguments for the normalization layer before providing the dimension. Useful when using GroupNorm layers are being used to specify the number of groups.", "items": {}, "title": "Normalization Pre Args", "type": "array" }, "normalization_post_args": { "default": [], "description": "Arguments for the normalization layer after providing the dimension.", "items": {}, "title": "Normalization Post Args", "type": "array" }, "normalization_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the normalization layer", "title": "Normalization Kwargs", "type": "object" }, "activation": { "default": "relu", "description": "Activation function to use in the block.", "title": "Activation", "type": "string" }, "activation_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the activation function.", "title": "Activation Kwargs", "type": "object" }, "sequence": { "default": "CNA", "description": "Sequence of operations in the block.", "enum": [ "C", "AC", "CA", "CD", "CN", "DC", "NC", "ACD", "ACN", "ADC", "ANC", "CAD", "CAN", "CDA", "CDN", "CNA", "CND", "DAC", "DCA", "DCN", "DNC", "NAC", "NCA", "NCD", "NDC", "ACDN", "ACND", "ADCN", "ADNC", "ANCD", "ANDC", "CADN", "CAND", "CDAN", "CDNA", "CNAD", "CNDA", "DACN", "DANC", "DCAN", "DCNA", "DNAC", "DNCA", "NACD", "NADC", "NCAD", "NCDA", "NDAC", "NDCA" ], "title": "Sequence", "type": "string" }, "drop_prob": { "default": 0.0, "description": "Dropout probability.", "title": "Drop Prob", "type": "number" }, "dim": { "description": "Input channel dimension of the block.", "title": "Dim", "type": "integer" }, "out_dim": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Output channel dimension of the block. If None, it will be set to `dim`.", "title": "Out Dim" }, "expansion_ratio": { "default": 6.0, "description": "Expansion ratio for the block.", "title": "Expansion Ratio", "type": "number" }, "se_reduction_ratio": { "default": 4.0, "description": "Squeeze-and-excitation reduction ratio.", "title": "Se Reduction Ratio", "type": "number" } }, "required": [ "dim" ] }
- Config:
arbitrary_types_allowed: bool = True
extra: str = ignore
validate_default: bool = True
validate_assignment: bool = True
validate_return: bool = True
- Fields:
- Validators:
validate
»all fields
validate_before
»all fields
-
field dim:
int
[Required]# Input channel dimension of the block.
- Validated by:
-
field out_dim:
int
|None
= None# Output channel dimension of the block. If None, it will be set to dim.
- Validated by:
-
field expansion_ratio:
float
= 6.0# Expansion ratio for the block.
- Validated by:
-
field se_reduction_ratio:
float
= 4.0# Squeeze-and-excitation reduction ratio.
- Validated by:
-
field kernel_size:
int
= 3# Kernel size for the convolutional layers.
- Validated by:
-
field activation:
str
= 'relu'# Activation function to use in the block.
- Validated by:
-
field normalization:
str
= 'batchnorm3d'# Normalization layer to use in the block.
- Validated by:
-
field in_channels:
None
= None# Use dim instead
- Validated by:
-
field out_channels:
None
= None# Use expansion_ratio instead
- Validated by:
- class vision_architectures.blocks.mbconv_3d.MBConv3D(config={}, checkpointing_level=0, **kwargs)[source]#
Bases:
Module
Mobile Inverted Residual Bottleneck Block. This class is designed for 3D input eg. medical images, videos etc.
- __init__(config={}, checkpointing_level=0, **kwargs)[source]#
Initialize the MBConv3D block. Activation checkpointing level 2.
- Parameters:
config (
MBConv3DConfig
) – An instance of the Config class that contains all the configuration parameters. It can also be passed as a dictionary and the instance will be created automatically.checkpointing_level (
int
) – The level of checkpointing to use for activation checkpointing. Refer toActivationCheckpointing
for more details.**kwargs – Additional keyword arguments for configuration.
- forward(x, channels_first=True)[source]#
Forward pass of the MBConv3D block.
- Parameters:
x (
Tensor
) – Tensor of shape (B, C, Z, Y, X) or (B, Z, Y, X, C) representing the input features.channels_first (
bool
) – Whether the inputs are in channels first format (B, C, …) or not (B, …, C).
- Return type:
Tensor
- Returns:
Tensor of shape (B, C, Z, Y, X) or (B, Z, Y, X, C) representing the output features.