pub struct ConvNextBlock { /* private fields */ }Expand description
A single ConvNeXt block.
All weight tensors are flat row-major Vec<f32>.
Implementations§
Source§impl ConvNextBlock
impl ConvNextBlock
Sourcepub fn new(cfg: ConvNextConfig, rng: &mut LcgRng) -> VisionResult<Self>
pub fn new(cfg: ConvNextConfig, rng: &mut LcgRng) -> VisionResult<Self>
Construct a new block with random depthwise / pointwise weights, zeroed
depthwise bias, identity LayerNorm affine, and layer-scale gamma set to
cfg.layer_scale_init.
Kernels and pointwise weights use a Kaiming-ish scaled normal initialisation drawn from the deterministic LCG RNG.
§Errors
Propagates configuration validation from ConvNextConfig::new.
Sourcepub fn config(&self) -> &ConvNextConfig
pub fn config(&self) -> &ConvNextConfig
Read-only access to the block configuration.
Sourcepub fn dw_kernel_mut(&mut self) -> &mut [f32]
pub fn dw_kernel_mut(&mut self) -> &mut [f32]
Mutable access to the depthwise kernel (used for tests that install an identity / delta kernel).
Sourcepub fn dw_bias_mut(&mut self) -> &mut [f32]
pub fn dw_bias_mut(&mut self) -> &mut [f32]
Mutable access to the depthwise bias.
Sourcepub fn depthwise_conv(&self, x: &[f32]) -> VisionResult<Vec<f32>>
pub fn depthwise_conv(&self, x: &[f32]) -> VisionResult<Vec<f32>>
Depthwise convolution: each channel c is convolved with its own
kernel × kernel filter, zero-padded “same” (pad = (k-1)/2),
stride 1, plus per-channel bias.
Input / output are (C, H, W) flat.
§Errors
DimensionMismatch if x.len() != C·H·W.
Sourcepub fn channel_layernorm(&self, x: &[f32]) -> VisionResult<Vec<f32>>
pub fn channel_layernorm(&self, x: &[f32]) -> VisionResult<Vec<f32>>
Channel LayerNorm: at each spatial position (h, w), gather the C
channel values, normalise to zero-mean / unit-variance (ε = 1e-6),
then apply per-channel affine γ · x̂ + β.
Input / output are (C, H, W) flat.
§Errors
DimensionMismatch if x.len() != C·H·W.
Sourcepub fn forward(&self, x: &[f32]) -> VisionResult<Vec<f32>>
pub fn forward(&self, x: &[f32]) -> VisionResult<Vec<f32>>
Forward pass: (C·H·W) → (C·H·W).
See the module docs for the full pipeline. When layer_scale_init is
0.0, the residual branch is multiplied by zero so forward(x) == x.
§Errors
DimensionMismatchifx.len() != C·H·W.NonFiniteif the output contains non-finite values.