Views
No views yet
nn.Module (see the ViT/TransformerBlock/PatchEmbedding
classes in the course notebook), not a 🤗 Transformers model. To use it, recreate the
architecture from the notebook and load the weights:1import json, torch
2from huggingface_hub import hf_hub_download
3
4cfg = json.load(open(hf_hub_download("liangnanying/vit-scratch-cifar10", "config.json")))
5model = ViT( # <-- the ViT class from the notebook
6 img_size=cfg["img_size"], patch_size=cfg["patch_size"],
7 num_classes=cfg["num_classes"], embed_dim=cfg["embed_dim"],
8 depth=cfg["depth"], num_heads=cfg["num_heads"], dropout=cfg["dropout"],
9)
10sd = torch.load(hf_hub_download("liangnanying/vit-scratch-cifar10", "vit_scratch_cifar10.pt"), map_location="cpu")
11model.load_state_dict(sd)
12model.eval()