
ViT patch embedding (Geron Ch 17, morie.fn grvit)
Source:R/geron_train_native.R
morie_geron_vit_patch_embedding.RdRow-major patches (top-to-bottom, left-to-right), each flattened ROW-MAJOR over (row, col, channel), projected by E, with the CLS token prepended and the positional table added.
Examples
set.seed(4)
img <- array(rnorm(8 * 8), c(8, 8))
E <- matrix(rnorm(16 * 4, 0, 0.3), 16, 4)
r <- morie_geron_vit_patch_embedding(img, patch_size = 4, E = E)
str(r, max.level = 1)
#> List of 6
#> $ embeddings: num [1:5, 1:4] 0 -0.535 -0.655 -0.192 0.682 ...
#> $ patches : num [1:4, 1:16] 0.217 -0.754 1.636 -0.227 1.897 ...
#> $ n_patches : int 4
#> $ d_model : int 4
#> $ estimate : num [1:5, 1:4] 0 -0.535 -0.655 -0.192 0.682 ...
#> $ n : int 5