Struct Conv2D

Source
pub struct Conv2D {
    pub in_channels: usize,
    pub out_channels: usize,
    pub kernel_size: (usize, usize),
    pub stride: (usize, usize),
    pub padding: (usize, usize),
    pub weights: Vec<Vec<Vec<Vec<f64>>>>,
    pub bias: Vec<f64>,
}
Expand description

Represents a 2D convolution layer

Fields§

§in_channels: usize

Number of input channels

§out_channels: usize

Number of output channels (number of filters)

§kernel_size: (usize, usize)

Kernel size (height, width)

§stride: (usize, usize)

Stride (height, width)

§padding: (usize, usize)

Padding (height, width)

§weights: Vec<Vec<Vec<Vec<f64>>>>

Weights (out_channels, in_channels, kernel_height, kernel_width)

§bias: Vec<f64>

Biases (out_channels)

Implementations§

Source§

impl Conv2D

Source

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

Creates a new Conv2D layer

§Arguments
  • in_channels - Number of input channels
  • out_channels - Number of output channels
  • kernel_size - Size of the convolving kernel (height, width)
  • stride - Stride of the convolution (height, width)
  • padding - Zero-padding added to both sides of the input (height, width)
§Example
use algos::ml::deep::conv::Conv2D;
let conv = Conv2D::new(3, 64, (3, 3), (1, 1), (1, 1));
Source

pub fn output_shape( &self, input_height: usize, input_width: usize, ) -> (usize, usize)

Computes the output shape for given input dimensions

§Arguments
  • input_height - Height of input
  • input_width - Width of input
§Returns
  • Tuple of (output_height, output_width)
Source

pub fn forward( &self, input: &[Vec<Vec<Vec<f64>>>], ) -> (Vec<Vec<Vec<Vec<f64>>>>, Conv2DCache)

Forward pass of the convolution layer

§Arguments
  • input - Input tensor of shape (batch_size, in_channels, height, width)
§Returns
  • Output tensor of shape (batch_size, out_channels, output_height, output_width)
  • Cache for backward pass
Source

pub fn backward( &self, grad_output: &[Vec<Vec<Vec<f64>>>], cache: &Conv2DCache, ) -> (Vec<Vec<Vec<Vec<f64>>>>, Conv2DGradients)

Backward pass of the convolution layer

§Arguments
  • grad_output - Gradient of the loss with respect to the output
  • cache - Cache from forward pass
§Returns
  • Gradient with respect to input
  • Gradient with respect to weights
  • Gradient with respect to bias

Trait Implementations§

Source§

impl Clone for Conv2D

Source§

fn clone(&self) -> Conv2D

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Conv2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Conv2D

§

impl RefUnwindSafe for Conv2D

§

impl Send for Conv2D

§

impl Sync for Conv2D

§

impl Unpin for Conv2D

§

impl UnwindSafe for Conv2D

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V