pub trait TryConv2D<Stride, Padding, Dilation, Groups>: Sized {
    type Convolved;
    type Error: Debug;

    // Required method
    fn try_conv2d(
        self,
        stride: Stride,
        padding: Padding,
        dilation: Dilation,
        groups: Groups
    ) -> Result<Self::Convolved, Self::Error>;

    // Provided method
    fn conv2d(
        self,
        stride: Stride,
        padding: Padding,
        dilation: Dilation,
        groups: Groups
    ) -> Self::Convolved { ... }
}
Expand description

Apply the 2d convolution to a tensor.

Const dims require nightly:

#![feature(generic_const_exprs)]
let x: Tensor<Rank4<2, 3, 32, 32>, f32, _> = dev.sample_normal();
let w: Tensor<Rank4<6, 3, 3, 3>, f32, _> = dev.sample_normal();
let y = (x, w).conv2d(
    Const::<1>, // stride
    Const::<0>, // padding
    Const::<1>, // dilation
    Const::<1>, // groups
);

usize dims can be used on stable:

let x: Tensor<_, f32, _> = dev.sample_normal_like(&(
    2,  // batch size
    3,  // input channels
    32, // height
    32, // width
));
let w: Tensor<_, f32, _> = dev.sample_normal_like(&(
    6, // output channels
    3, // input channels
    3, // kernel size
    3, // kernel size
));
let y = (x, w).conv2d(
    1, // stride
    0, // padding
    1, // dilation
    1, // groups
);

Required Associated Types§

Required Methods§

source

fn try_conv2d( self, stride: Stride, padding: Padding, dilation: Dilation, groups: Groups ) -> Result<Self::Convolved, Self::Error>

Fallibly applies a 2D convolution to the input tensor.

Provided Methods§

source

fn conv2d( self, stride: Stride, padding: Padding, dilation: Dilation, groups: Groups ) -> Self::Convolved

Applies a 2D convolution to the input tensor.

Implementations on Foreign Types§

source§

impl<InpChan, OutChan, Kernel, Stride, Padding, Dilation, Groups, H, W, E, D, T> TryConv2D<Stride, Padding, Dilation, Groups> for (Tensor<(InpChan, H, W), E, D, T>, Tensor<(OutChan, <InpChan as Div<Groups>>::Output, Kernel, Kernel), E, D>)where InpChan: Dim + Div<Groups>, OutChan: Dim, Kernel: Dim, Stride: Dim, Padding: Dim, Dilation: Dim, Groups: Dim, H: Dim, W: Dim, E: Dtype, D: Conv2DKernel<E> + ReshapeKernel<E>, T: Tape<E, D>, <InpChan as Div<Groups>>::Output: Dim, (H, Kernel): TryConv2D<Stride, Padding, Dilation, Groups>, (W, Kernel): TryConv2D<Stride, Padding, Dilation, Groups>, <(H, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved: Dim, <(W, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved: Dim,

§

type Convolved = Tensor<(OutChan, <(H, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved, <(W, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved), E, D, T>

§

type Error = <D as HasErr>::Err

source§

fn try_conv2d( self, stride: Stride, padding: Padding, dilation: Dilation, groups: Groups ) -> Result<Self::Convolved, Self::Error>

source§

impl<const KERNEL: usize, const STRIDE: usize, const PADDING: usize, const DILATION: usize, Groups: Dim, const DIM: usize> TryConv2D<Const<STRIDE>, Const<PADDING>, Const<DILATION>, Groups> for (Const<DIM>, Const<KERNEL>)where Const<{ _ }>: Sized,

§

type Convolved = Const<{ (DIM + 2 * PADDING - DILATION * (KERNEL - 1) - 1) / STRIDE + 1 }>

§

type Error = Infallible

source§

fn try_conv2d( self, _: Const<STRIDE>, _: Const<PADDING>, _: Const<DILATION>, _: Groups ) -> Result<Self::Convolved, Self::Error>

source§

impl<Kernel: Dim, Stride: Dim, Padding: Dim, Dilation: Dim, Groups: Dim> TryConv2D<Stride, Padding, Dilation, Groups> for (usize, Kernel)

§

type Convolved = usize

§

type Error = Infallible

source§

fn try_conv2d( self, stride: Stride, padding: Padding, dilation: Dilation, _: Groups ) -> Result<Self::Convolved, Self::Error>

source§

impl<InpChan, OutChan, Kernel, Stride, Padding, Dilation, Groups, Batch, H, W, E, D, T> TryConv2D<Stride, Padding, Dilation, Groups> for (Tensor<(Batch, InpChan, H, W), E, D, T>, Tensor<(OutChan, <InpChan as Div<Groups>>::Output, Kernel, Kernel), E, D>)where InpChan: Dim + Div<Groups>, OutChan: Dim, Kernel: Dim, Stride: Dim, Padding: Dim, Dilation: Dim, Groups: Dim, Batch: Dim, H: Dim, W: Dim, E: Dtype, D: Conv2DKernel<E>, T: Tape<E, D>, <InpChan as Div<Groups>>::Output: Dim, (H, Kernel): TryConv2D<Stride, Padding, Dilation, Groups>, (W, Kernel): TryConv2D<Stride, Padding, Dilation, Groups>, <(H, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved: Dim, <(W, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved: Dim,

§

type Convolved = Tensor<(Batch, OutChan, <(H, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved, <(W, Kernel) as TryConv2D<Stride, Padding, Dilation, Groups>>::Convolved), E, D, T>

§

type Error = <D as HasErr>::Err

source§

fn try_conv2d( self, stride: Stride, padding: Padding, dilation: Dilation, groups: Groups ) -> Result<Self::Convolved, Self::Error>

Implementors§