pub struct VisionTransformer {
pub patch_embed: PatchEmbedding,
pub cls_token: Tensor,
pub pos_embed: Tensor,
pub encoder_blocks: Vec<TransformerEncoderBlock>,
pub ln_gamma: Tensor,
pub ln_beta: Tensor,
pub head_w: Tensor,
pub head_b: Tensor,
pub embed_dim: usize,
pub num_classes: usize,
}Expand description
Vision Transformer (ViT) for image classification (inference-mode).
Architecture:
- Patch embedding
- Prepend learnable class token
- Add learnable position embeddings
- N transformer encoder blocks
- Layer norm on output
- Linear classification head on class token
Input: [batch, H, W, C] (NHWC)
Output: [batch, num_classes]
Fields§
§patch_embed: PatchEmbedding§cls_token: TensorClass token: [1, embed_dim]
pos_embed: TensorPosition embeddings: [1, num_patches + 1, embed_dim]
encoder_blocks: Vec<TransformerEncoderBlock>Transformer encoder blocks
ln_gamma: TensorFinal layer norm gamma: [embed_dim]
ln_beta: TensorFinal layer norm beta: [embed_dim]
head_w: TensorClassification head weight: [embed_dim, num_classes]
head_b: TensorClassification head bias: [num_classes]
embed_dim: usize§num_classes: usizeImplementations§
Auto Trait Implementations§
impl Freeze for VisionTransformer
impl RefUnwindSafe for VisionTransformer
impl Send for VisionTransformer
impl Sync for VisionTransformer
impl Unpin for VisionTransformer
impl UnsafeUnpin for VisionTransformer
impl UnwindSafe for VisionTransformer
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
Mutably borrows from an owned value. Read more
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>
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 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>
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