-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.py
41 lines (35 loc) · 1.08 KB
/
utils.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
import numpy as np
def get_model(args):
model = None
if args.model=='mlp_mixer':
from mlp_mixer import MLPMixer
model = MLPMixer(
in_channels=3,
img_size=args.size,
hidden_size=args.hidden_size,
patch_size = args.patch_size,
hidden_c = args.hidden_c,
hidden_s = args.hidden_s,
num_layers = args.num_layers,
num_classes=args.num_classes,
drop_p=args.drop_p,
off_act=args.off_act,
is_cls_token=args.is_cls_token
)
else:
raise ValueError(f"No such model: {args.model}")
return model.to(args.device)
def rand_bbox(size, lam):
W = size[2]
H = size[3]
cut_rat = np.sqrt(1. - lam)
cut_w = np.int(W * cut_rat)
cut_h = np.int(H * cut_rat)
# uniform
cx = np.random.randint(W)
cy = np.random.randint(H)
bbx1 = np.clip(cx - cut_w // 2, 0, W)
bby1 = np.clip(cy - cut_h // 2, 0, H)
bbx2 = np.clip(cx + cut_w // 2, 0, W)
bby2 = np.clip(cy + cut_h // 2, 0, H)
return bbx1, bby1, bbx2, bby2