MBConvBlock¶
- class MBConvBlock(in_planes, out_planes, expand_ratio, kernel_size, stride, reduction_ratio=4)[source]¶
Mobile Inverted Residual Bottleneck block.
This block implements the MBConv block used in EfficientNet architectures. It consists of expansion, depthwise convolution, squeeze-and-excitation, and projection phases with optional residual connection.
- _expand_conv¶
1x1 convolution for channel expansion.
- Type:
nn.Module
- _bn0¶
Batch normalization after expansion.
- Type:
nn.Module
- _swish¶
SiLU activation function.
- Type:
SiLU
- _depthwise_conv¶
Depthwise convolution layer.
- Type:
- _bn1¶
Batch normalization after depthwise convolution.
- Type:
nn.BatchNorm2d
- _se_reduce¶
Squeeze-and-excitation reduction layer.
- Type:
- _se_expand¶
Squeeze-and-excitation expansion layer.
- Type:
- _project_conv¶
1x1 convolution for projection to output channels.
- Type:
- _bn2¶
Batch normalization after projection.
- Type:
nn.BatchNorm2d
Example
>>> block = MBConvBlock( ... in_planes=32, out_planes=64, expand_ratio=6, ... kernel_size=3, stride=2 ... ) >>> x = torch.randn(1, 32, 64, 64) >>> output = block(x) >>> output.shape ... torch.Size([1, 64, 32, 32])
Initialize MBConvBlock.
Creates a mobile inverted residual bottleneck block with expansion, depthwise convolution, squeeze-and-excitation, and projection.
- Parameters:
in_planes (int) – Number of input channels.
out_planes (int) – Number of output channels.
expand_ratio (int) – Expansion ratio for the hidden dimension.
kernel_size (int) – Size of the depthwise convolution kernel.
stride (int) – Stride of the depthwise convolution.
reduction_ratio (int) – Reduction ratio for squeeze-and-excitation. Defaults to 4.
Methods
Forward pass through MBConvBlock.
Attributes
training- forward(x)[source]¶
Forward pass through MBConvBlock.
Applies expansion, depthwise convolution, squeeze-and-excitation, projection, and optional residual connection.
- Parameters:
x (torch.Tensor) – (B, C_in, H, W). Input tensor.
self (MBConvBlock)
- Returns:
(B, C_out, H’, W’). Output tensor after block processing.
- Return type: