Skip to main content

Im2Col

Struct Im2Col 

Source
pub struct Im2Col<'a, T> {
    pub image: NdTensorView<'a, T, 3>,
    pub row_offsets: RowOffsets,
    pub col_offsets: ColOffsets,
    pub n_cols: usize,
    pub n_rows: usize,
    pub max_y_offset: i32,
    pub max_x_offset: i32,
}
Expand description

A matrix formed by unrolling patches of an image into columns.

Each column of the matrix corresponds to a different spatial patch of the image, and each row is a different location within the patch. The matrix can be used as the right-hand input of a matrix multiplication in order to perform a convolution.

The input image has shape [C, H, W] and is transformed into a matrix with shape [C * Kh * kW, Oh * Ow] where Kh/Kw are convolution kernel sizes and Oh/Ow are the number of patches in the Y and X directions. Given a weight matrix W of shape [M, C * Kh * kW] the matrix multiplication W @ im2col(image) produces an output of shape [M, Oh * Ow] which can be reshaped into the convolution output [M, Oh, Ow].

The matrix is virtual as it is not materialized fully in memory. Instead blocks of the matrix are materialized during computation.

Fields§

§image: NdTensorView<'a, T, 3>§row_offsets: RowOffsets

Map of im2col row index to position within image patch (channel, kernel_y, kernel_x) pre-multiplied by corresponding stride.

The arrays may be padded to a multiple of a step size specified by the GEMM kernel. n_rows contains the actual number of rows in the virtual matrix.

§col_offsets: ColOffsets

Map of im2col column index to (y, x) coordinate of top-level corner of patch in image, pre-multiplied by corresponding stride.

The arrays may be padded to a multiple of a step size specified by the GEMM kernel. n_cols contains the actual number of columns in the virtual matrix.

§n_cols: usize

Number of columns in the im2col matrix.

§n_rows: usize

Number of rows in the im2col matrix.

§max_y_offset: i32

Maximum valid sum of row_offsets.y + col_offsets.y. Values above this correspond to the padding region.

§max_x_offset: i32

Maximum valid sum of row_offsets.x + col_offsets.x. Values above this correspond to the padding region.

Implementations§

Source§

impl<T: Copy + Default> Im2Col<'_, T>

Source

pub fn rows(&self) -> usize

Return the number of rows in the im2col matrix.

Source

pub fn cols(&self) -> usize

Return the number of columns in the im2col matrix.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Im2Col<'a, T>

§

impl<'a, T> RefUnwindSafe for Im2Col<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Im2Col<'a, T>

§

impl<'a, T> Sync for Im2Col<'a, T>

§

impl<'a, T> Unpin for Im2Col<'a, T>

§

impl<'a, T> UnsafeUnpin for Im2Col<'a, T>

§

impl<'a, T> UnwindSafe for Im2Col<'a, T>
where T: RefUnwindSafe,

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> 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, 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.