Images as Linear AlgebraMedium
ViT Patch Embedding
~18 mincode completion
Implement vit_patch_embed(image, P, E, cls, pos) returning the (N+1,D) token matrix z0.
Where this shows up
~18 min
••••••••••••••••
8 employers weight this skill
4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 92.
Python
import numpy as np
def vit_patch_embed(image, P, E, cls, pos):
"""
Turn an image into the ViT input token sequence.
Args:
image: array (H, W, C), H and W divisible by P
P: patch side length
E: projection matrix (P*P*C, D)
cls: class token, shape (D,)
pos: position vectors, shape (N+1, D)
Returns:
array (N+1, D): class token first, then patches in row-major order
"""
# YOUR CODE HERE
pass