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: RowOffsetsMap 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: ColOffsetsMap 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: usizeNumber of columns in the im2col matrix.
n_rows: usizeNumber of rows in the im2col matrix.
max_y_offset: i32Maximum valid sum of row_offsets.y + col_offsets.y. Values above this
correspond to the padding region.
max_x_offset: i32Maximum valid sum of row_offsets.x + col_offsets.x. Values above this
correspond to the padding region.
Implementations§
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> 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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