-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_imagenet1k.py
69 lines (51 loc) · 1.32 KB
/
train_imagenet1k.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# %%
import torch as t
from torch import nn
from tqdm import tqdm
from datasets import load_dataset, DatasetDict
from nanovit import ViT, ViTConfig, build_preprocessor
from nanovit.schedule import cosine_schedule
dd: DatasetDict = load_dataset("uoft-cs/cifar100") # type: ignore
feats = dd['train'].features
# %%
# ███████████████████████████████████ config ███████████████████████████████████
vit_cfg = ViTConfig(
n_layers=8,
d_model=192,
d_proj=100, # 2 classes
image_res=(224, 224),
patch_size=16,
n_heads=6,
norm_data=(
(0.48145466, 0.4578275, 0.40821073),
(0.26862954, 0.26130258, 0.27577711),
),
mlp_mult=4,
)
nclasses = 1000
nepochs = 90
bs = 1024
lr = 1e-3
wd = 1e-4
grad_clip = 1.0
warmup_steps = 10_000
sched = cosine_schedule
loss = "softmax_xent"
# pool_type: gap
# posemb: sincos2d
# bfloat16
# mixup: 0.2
# 99% train test split
# loss = "softmax_xent"
# inception crop(224) flip_lr randaug(2, 10)
# resize_small(256) central_crop(224)
# transforms.RandAugment(num_ops=2, magnitude=10),
val_bs = bs * 2
device = (
"cuda"
if t.cuda.is_available()
else "mps"
if t.backends.mps.is_available()
else "cpu"
)
# %%