Skip to main content

VitPatchEmbed

Struct VitPatchEmbed 

Source
pub struct VitPatchEmbed { /* private fields */ }
Expand description

ViT patch-embedding layer with [CLS] token and learnable positions.

Implementations§

Source§

impl VitPatchEmbed

Source

pub fn new(config: VitPatchConfig, rng: &mut VisionRng) -> VisionResult<Self>

Construct a new patch embedder with random parameters.

The projection weight is initialised N(0, 1/√patch_dim) (the fan-in scaling used by the reference implementations); biases are near-zero, the class token is N(0, 0.02) (ViT’s truncated-normal scale), and the positional embedding is N(0, 0.02).

§Errors

Propagates VitPatchConfig::validate failures.

Source

pub fn config(&self) -> &VitPatchConfig

Read-only access to the configuration.

Source

pub fn n_patches(&self) -> usize

Number of image patches: (image_size / patch_size)².

Source

pub fn forward(&self, image: &[f32]) -> VisionResult<Vec<f32>>

Embed an image into a token sequence.

image must be [n_channels × image_size × image_size] row-major (CHW). The returned sequence is [(n_patches + 1) × d_model]: a prepended [CLS] token followed by the n_patches projected patch tokens, with the learnable positional embedding added element-wise.

§Errors

Auto Trait Implementations§

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