forked from anonymous-15816/ART
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
149 lines (113 loc) · 6.14 KB
/
plot.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
import argparse
from trainer.train import *
from models.model_resnet import *
import myData.iDataset
import myData.iDataLoader
from utils import *
from sklearn.utils import shuffle
import trainer.trainer_warehouse
import trainer.evaluator
from arguments import *
#parser.add_argument("")
args = get_args()
#seed
seed = args.seed
set_seed(seed)
dataset = myData.iDataset.CIFAR10()
shuffle_idx = shuffle(np.arange(dataset.classes), random_state = seed)
#shuffle_idx = np.genfromtxt('C:/Users/Hongjun/Desktop/Cifar100_SuperClass_labelnum.csv',delimiter=',',encoding="UTF-8", skip_header=0, dtype = np.int32)
#shuffle_idx[0] = 20
print(shuffle_idx)
tasknum = (dataset.classes - args.start_classes) // args.step_size + 1
myNet = resnet32(num_classes=dataset.classes, tasknum=tasknum).cuda()
if args.dataset == 'CIFAR100':
loader = None
else:
loader = dataset.loader
train_dataset_loader = myData.iDataLoader.IncrementalLoader(dataset.train_data,
dataset.train_labels,
dataset.classes,
args.step_size,
args.memory_size,
'train',
transform=dataset.train_transform,
loader=loader,
shuffle_idx=shuffle_idx,
base_classes=args.start_classes,
approach= "wa",
)
evaluate_dataset_loader = myData.iDataLoader.IncrementalLoader(dataset.train_data,
dataset.train_labels,
dataset.classes,
args.step_size,
args.memory_size,
'train',
transform=dataset.train_transform,
loader=loader,
shuffle_idx=shuffle_idx,
base_classes=args.start_classes,
approach= "wa",
)
test_dataset_loader = myData.iDataLoader.IncrementalLoader(dataset.test_data,
dataset.test_labels,
dataset.classes,
args.step_size,
args.memory_size,
'test',
transform=dataset.test_transform,
loader=loader,
shuffle_idx=shuffle_idx,
base_classes=args.start_classes,
approach= "wa",
)
result_dataset_loaders = myData.iDataLoader.make_ResultLoaders(dataset.test_data,
dataset.test_labels,
dataset.classes,
args.step_size,
transform=dataset.test_transform,
loader=loader,
shuffle_idx = shuffle_idx,
base_classes = args.start_classes
)
train_iterator = torch.utils.data.DataLoader(train_dataset_loader, batch_size=args.batch_size, shuffle=True, drop_last=False)
evaluator_iterator = torch.utils.data.DataLoader(evaluate_dataset_loader, batch_size=args.batch_size, shuffle=True, drop_last=False)
test_iterator = torch.utils.data.DataLoader(test_dataset_loader, batch_size=100, shuffle=False)
optimizer = optim.SGD(myNet.parameters(), args.lr, momentum=0.9,
weight_decay=5e-4, nesterov=True)
myTrainer = trainer.trainer_warehouse.TrainerFactory.get_trainer(train_iterator, test_iterator, dataset, myNet, args, optimizer)
testType = "trainedClassifier"
myEvaluator = trainer.evaluator.EvaluatorFactory.get_evaluator(testType, classes=dataset.classes)
train_start = 0
train_end = args.start_classes
test_start = 0
test_end = args.start_classes
total_epochs = args.nepochs
schedule = np.array(args.schedule)
results = {}
for head in ['all', 'prev_new', 'task', 'cheat']:
results[head] = {}
results[head]['correct'] = []
results[head]['correct_5'] = []
results[head]['stat'] = []
results['task_soft_1'] = np.zeros((tasknum, tasknum))
results['task_soft_5'] = np.zeros((tasknum, tasknum))
print(tasknum)
correct_list = []
stat_list = []
task_confidence_list = []
get_confidence = False
task_error = []
import matplotlib.pyplot as plt
w = 10
h = 10
fig = plt.figure(figsize=(10, 10))
columns = 10
rows = 10
# temp_sortHard = var_grad_classRank[0][:26]
#img = myTrainer.train_data_iterator.dataset.data[(3 * 500 - 1)]
#plt.imshow(img)
for i in range(1, 10):
img = myTrainer.train_data_iterator.dataset.data[(i*5000 - 1)]
fig.add_subplot(rows, columns, i)
plt.imshow(img)
plt.show()