conv2d_blocks
2D convolution block with optional normalization and activation.
Classes:
-
Conv2dBlockβSingle
nn.Conv2d(ornn.ConvTranspose2d) + optional norm + optional activation.
Conv2dBlock [source] ΒΆ
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.