Skip to main content

Conv2d

Struct Conv2d 

Source
pub struct Conv2d<D: Dtype, IT, OT, const RANK: usize> {
    pub in_channels: usize,
    pub out_channels: usize,
    pub kernel_h: usize,
    pub kernel_w: usize,
    pub stride_h: usize,
    pub stride_w: usize,
    pub padding_h: usize,
    pub padding_w: usize,
    pub groups: usize,
    pub has_bias: bool,
    /* private fields */
}
Expand description

2-D convolution layer: output = conv2d(input, weight) [+ b]

Input shape: [N, C_in, H_in, W_in ] Output shape: [N, C_out, H_out, W_out]

where: H_out = (H_in + 2*padding_h - kernel_h) / stride_h + 1 W_out = (W_in + 2*padding_w - kernel_w) / stride_w + 1

Type parameters:

  • D — element dtype
  • IT — input tensor type (rank 4: [N, C_in, H, W])
  • OT — output tensor type (rank 4: [N, C_out, H, W])
  • RANK — tensor rank; must be 4 for a valid 2-D convolution

Tensor bounds are on impls, not the struct, so SymTensor can have its own Layer impl without a coherence conflict.

Fields§

§in_channels: usize

Number of input channels.

§out_channels: usize

Number of output channels.

§kernel_h: usize

Convolution kernel height.

§kernel_w: usize

Convolution kernel width.

§stride_h: usize

Vertical stride.

§stride_w: usize

Horizontal stride.

§padding_h: usize

Vertical zero-padding.

§padding_w: usize

Horizontal zero-padding.

§groups: usize

Number of blocked/grouped connections (1 = standard convolution).

§has_bias: bool

Whether to add a learned bias.

Implementations§

Source§

impl<D: Dtype, IT, OT, const RANK: usize> Conv2d<D, IT, OT, RANK>

Source

pub fn new( in_channels: usize, out_channels: usize, kernel_size: (usize, usize), stride: (usize, usize), padding: (usize, usize), has_bias: bool, ) -> Self

Create a new Conv2d layer.

  • kernel_size(height, width) of the convolution kernel
  • stride(height, width) step between kernel applications
  • padding(height, width) zero-padding added to each spatial side
Source

pub fn new_grouped( in_channels: usize, out_channels: usize, kernel_size: (usize, usize), stride: (usize, usize), padding: (usize, usize), has_bias: bool, groups: usize, ) -> Self

Creates a new grouped Conv2d layer (see Conv2d::groups).

Trait Implementations§

Source§

impl<D: Dtype, IT: Tensor<D, RANK> + EagerTensor, OT: Tensor<D, RANK>, const RANK: usize> Layer<IT> for Conv2d<D, IT, OT, RANK>

Source§

type Output = OT

This layer’s output type.
Source§

fn call(&self, _input: IT) -> Self::Output

Applies this layer to input.
Source§

impl<D: Dtype, const RANK: usize> Layer<SymTensor> for Conv2d<D, SymTensor, SymTensor, RANK>

Source§

type Output = SymTensor

This layer’s output type.
Source§

fn call(&self, input: SymTensor) -> SymTensor

Applies this layer to input.

Auto Trait Implementations§

§

impl<D, IT, OT, const RANK: usize> Freeze for Conv2d<D, IT, OT, RANK>

§

impl<D, IT, OT, const RANK: usize> RefUnwindSafe for Conv2d<D, IT, OT, RANK>

§

impl<D, IT, OT, const RANK: usize> Send for Conv2d<D, IT, OT, RANK>
where D: Send, IT: Send, OT: Send,

§

impl<D, IT, OT, const RANK: usize> Sync for Conv2d<D, IT, OT, RANK>
where D: Sync, IT: Sync, OT: Sync,

§

impl<D, IT, OT, const RANK: usize> Unpin for Conv2d<D, IT, OT, RANK>
where D: Unpin, IT: Unpin, OT: Unpin,

§

impl<D, IT, OT, const RANK: usize> UnsafeUnpin for Conv2d<D, IT, OT, RANK>

§

impl<D, IT, OT, const RANK: usize> UnwindSafe for Conv2d<D, IT, OT, RANK>
where D: UnwindSafe, IT: UnwindSafe, OT: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.