Layers & Activations
DepthwiseConv2d
Direct depthwise 2D convolution over NCHW tensors without im2col matrix expansion overhead.
ochreml.nn.DepthwiseConv2d applies an independent spatial filter per input channel (producing in_channels * depth_multiplier output channels) directly in Rust without im2col expansion overhead. Pair with a 1x1 Conv2d for MobileNet-style depthwise separable blocks.
Import & Signature
import ochreml.nn as nn
dw = nn.DepthwiseConv2d(
in_channels,
depth_multiplier=1,
kernel_size=3,
stride=1,
padding=0,
dilation=1,
bias=True,
dtype="float32",
device=None,
seed=42,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
in_channels | int | required | Number of input channels. |
depth_multiplier | int | 1 | Number of depthwise filters per input channel (out_channels = in_channels * depth_multiplier). |
kernel_size | int | tuple[int, int] | 3 | Spatial kernel size (kH, kW). |
stride | int | tuple[int, int] | 1 | Convolution stride. |
padding | int | tuple[int, int] | 0 | Spatial zero-padding. |
dilation | int | tuple[int, int] | 1 | Kernel dilation. |
bias | bool | True | Learnable per-channel bias. |
dtype | str | "float32" | Tensor dtype. |
device | str | None | None | Target device. |
seed | int | 42 | Initialization seed. |
Usage Example
import ochreml.nn as nn
dw = nn.DepthwiseConv2d(in_channels=16, depth_multiplier=1, kernel_size=3, padding=1)
pw = nn.Conv2d(16, 32, kernel_size=1)
x = nn.Tensor.randn([4, 16, 16, 16])
out = pw(dw(x)) # shape: (4, 32, 16, 16)