ViT Patch Embedding

~18 mincode completion

Implement vit_patch_embed(image, P, E, cls, pos) returning the token matrix .

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
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.