conv2d_blocks
2D convolution block with optional normalization and activation.
Classes:
-
Conv2dBlock–Single
nn.Conv2d(ornn.ConvTranspose2d) + optional norm + optional activation.
Conv2dBlock
¶
Conv2dBlock(
in_channels: int,
out_channels: int,
kernel_size: int = 3,
*,
stride: int = 1,
padding: int = 0,
transposed: bool = False,
act: Union[str, Callable, None] = "relu",
act_first: bool = False,
act_kwargs: Optional[Dict[str, Any]] = None,
norm: Union[str, Callable, None] = "batch_norm",
norm_kwargs: Optional[Dict[str, Any]] = None,
bias: bool = False,
)
Bases: Module
Single nn.Conv2d (or nn.ConvTranspose2d) + optional norm + optional activation.
The 2D analogue of Conv3dBlock, with
stride, padding and transposed exposed so it can express the strided down-convs and
transposed up-convs of an SSD-style BEV backbone.
Shape
Input: \((B, C_\text{in}, H, W)\) Output: \((B, C_\text{out}, H', W')\)
Parameters:
-
in_channels(int) –Input channel count.
-
out_channels(int) –Output channel count.
-
kernel_size(int, default:3) –Conv kernel size.
-
stride(int, default:1) –Conv stride.
-
padding(int, default:0) –Conv padding.
-
transposed(bool, default:False) –Use
nn.ConvTranspose2dinstead ofnn.Conv2d(for upsampling). -
act(Union[str, Callable, None], default:'relu') –Activation, name resolved by
create_act.Nonedisables. -
act_first(bool, default:False) –If
True, run activation before normalization. -
act_kwargs(Optional[Dict[str, Any]], default:None) –Extra kwargs for the activation.
-
norm(Union[str, Callable, None], default:'batch_norm') –Normalization, name resolved by
create_norm(withdim=2).Nonedisables. -
norm_kwargs(Optional[Dict[str, Any]], default:None) –Extra kwargs for the normalization.
-
bias(bool, default:False) –Whether the conv has a bias term.