-
Notifications
You must be signed in to change notification settings - Fork 10
/
initialization.py
89 lines (81 loc) · 2.51 KB
/
initialization.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from torchvision import transforms
def init_crossx_params(backbone, datasetname):
epochs = 30
gamma1, gamma2, gamma3 = 0.0, 0.0, 0.0
lr = 0.0
if backbone is 'senet':
if datasetname is 'nabirds':
gamma1 = 0.1
gamma2 = 0.25
gamma3 = 0.5
elif datasetname in ['cubbirds', 'stcars']:
gamma1 = 1
gamma2 = 0.25
gamma3 = 1
elif datasetname is 'stdogs':
gamma1 = 1
gamma2 = 0.5
gamma3 = 1
elif datasetname is 'vggaricraft':
gamma1 = 0.5
gamma2 = 0.1
gamma3 = 0.1
else:
pass
elif backbone is 'resnet':
if datasetname in ['nabirds', 'cubbirds']:
gamma1 = 0.5
gamma2 = 0.25
gamma3 = 0.5
elif datasetname is 'stcars':
gamma1 = 1
gamma2 = 0.25
gamma3 = 1
elif datasetname is 'stdogs':
gamma1 = 0.01
gamma2 = 0.01
gamma3 = 1
elif datasetname is 'vggaricraft':
gamma1 = 0.5
gamma2 = 0.1
gamma3 = 0.5
else:
pass
else:
pass
if datasetname is 'stdogs':
lr = 0.001
else:
lr = 0.01
return gamma1, gamma2, gamma3, lr, epochs
def data_transform(datasetname=None):
if datasetname in ['cubbirds', 'nabirds', 'vggaircraft']:
return {
'trainval': transforms.Compose([
transforms.Resize((600, 600)),
transforms.RandomCrop((448, 448)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
'test': transforms.Compose([
transforms.Resize((600, 600)),
transforms.CenterCrop((448, 448)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])}
else:
return {
'trainval': transforms.Compose([
transforms.Resize((448, 448)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
]),
'test': transforms.Compose([
transforms.Resize((448, 448)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])}
if __name__ == "__main__":
pass