pub struct Conv2d {
pub weight: Parameter,
pub bias: Option<Parameter>,
pub in_channels: usize,
pub out_channels: usize,
pub kernel_size: usize,
pub stride: usize,
pub padding: usize,
}Expand description
2D convolutional layer.
Uses the im2col algorithm: reshape input patches into columns, then
compute the convolution as a single matmul per batch element.
Weight shape: [out_channels, in_channels * kernel_size * kernel_size].
Bias shape: [out_channels] (optional).
Forward: for each batch element:
x_col = input[b].im2col(k, stride, padding)→[col_height, num_patches]out_b = weight @ x_col→[out_channels, num_patches]- Stack all
out_b→[batch, out_channels, num_patches] - Add channel bias if present.
- Reshape to
[batch, out_channels, out_h, out_w].
All ops are individually tape-recorded — the autograd engine handles the entire backward pass via Kahn’s traversal.
Fields§
§weight: Parameter§bias: Option<Parameter>§in_channels: usize§out_channels: usize§kernel_size: usize§stride: usize§padding: usizeImplementations§
Trait Implementations§
Source§impl Module for Conv2d
impl Module for Conv2d
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Return clones of all learnable parameters.
Source§fn state_dict(&self, prefix: &str) -> HashMap<String, Tensor>
fn state_dict(&self, prefix: &str) -> HashMap<String, Tensor>
Serialize all parameters into a flat
name → Tensor map. Read moreAuto Trait Implementations§
impl Freeze for Conv2d
impl !RefUnwindSafe for Conv2d
impl Send for Conv2d
impl Sync for Conv2d
impl Unpin for Conv2d
impl UnsafeUnpin for Conv2d
impl !UnwindSafe for Conv2d
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more