Vision Transformer #
Patch embedding is an arbitrary-dimensional convolution. The spatial output is flattened into a token axis before the Transformer block, so the construction applies equally to one-dimensional signals, images, volumes, and higher-dimensional grids.
Configuration for a Transformer over patches from a d-dimensional spatial domain.
- batch : ℕ
Number of independent samples processed together.
- inChannels : ℕ
Number of channels in each input sample.
Extent of each spatial axis.
- patch : Conv d
Convolution that extracts and embeds patches.
- outDim : ℕ
Number of classifier outputs per sample.
- numHeads : ℕ
Number of attention heads.
- headDim : ℕ
Width of each attention head.
- ffnHidden : ℕ
Width of the feed-forward sublayer.
Instances For
Number of patch tokens.
Instances For
Number of flattened features passed to the classifier.
Instances For
Input shape (batch, inChannels, spatial...).
Instances For
Shape produced by patch embedding.
Instances For
Token shape (batch, sequence, embedding).
Instances For
Classifier output shape (batch, outDim).
Instances For
flatten the patch grid into a sequence and move channels to the final axis.
Instances For
Build patch embedding, one Transformer encoder block, and a linear classifier.