-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaces_wt_diff.py
More file actions
136 lines (85 loc) · 2.55 KB
/
places_wt_diff.py
File metadata and controls
136 lines (85 loc) · 2.55 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
import torch
import numpy as np
import pandas as pd
import resnet_XAI as models
import torch.utils.data
#dataset of methods
meth_eng = ['imb', 'ros', 'rem', 'dsm', 'eos']
paths=[
#base imbalanced
".../places/_aug_Plc_mod_25_0.pth",
".../places/_aug_Plc_mod_17_10.pth",
".../places/_aug_Plc_mod_27_100.pth",
#ROS
".../places/_ros_aug_Plc_mod_14_0.pth",
".../places/_ros_aug_Plc_mod_26_10.pth",
".../places/_ros_aug_Plc_mod_19_100.pth",
#REM
".../places/_rem_Plc_mod_38_0.pth",
".../places/_rem_Plc_mod_24_10.pth",
".../places/_rem_Plc_mod_19_100.pth",
#DSM
".../places/plc_DSM_0_comb.pth",
".../places/plc_DSM_10_comb.pth",
".../places/plc_DSM_100_comb.pth",
#EOS
".../places/plc_EOS_0_comb.pth",
".../places/plc_EOS_10_comb.pth",
".../places/plc_EOS_100_comb.pth",
]
# number of runs
runs = 3
#number of classes
num_cls = 5
#dimension of latent space (FE)
num_wts = 64
#files to collect output
imb = np.zeros((runs*num_cls,num_wts))
ros = np.zeros((runs*num_cls,num_wts))
rem = np.zeros((runs*num_cls,num_wts))
dsm = np.zeros((runs*num_cls,num_wts))
eos = np.zeros((runs*num_cls,num_wts))
#DA methods
meths = [imb,ros,rem,dsm,eos]
model_count = 0
for m in range(len(meth_eng)):
print('method',m,meth_eng[m])
row_count = 0
for r in range(runs):
print('run',r)
print('model',model_count)
print(paths[model_count])
use_norm = False
model = models.resnet56(num_classes=num_cls, use_norm=use_norm)
torch.cuda.set_device(0)
model = model.cuda(0)
model.load_state_dict(torch.load(paths[model_count]))
wt = model.linear.weight
wt = wt.detach().cpu().numpy()
print(wt.shape)
meth = meths[m]
print(meth.shape)
print(row_count,row_count+num_cls)
meth[row_count:row_count+num_cls,:]= wt
row_count+=num_cls
model_count+=1
for m in range(len(meth_eng)):
print(meth_eng[m])
print(meths[m])
print()
len_meth = len(meth_eng)
diffs = np.zeros(len_meth-1)
count=0
for m in range(1,len_meth):
diff = np.abs(meths[m] - meths[0])
diff = diff / np.abs(meths[0])
diff = np.mean(diff)
diffs[count]=diff
count+=1
print(diffs)
dif = diffs.reshape(1,-1)
pdf = pd.DataFrame(data=dif,columns=[['ROS',
'REMIX', 'DSM', 'EOS']])
f='.../figs/plc_wt_diffs.csv'
pdf.to_csv(f,index=False)