-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment3.py
69 lines (47 loc) · 1.3 KB
/
experiment3.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
from mnistdnn import mnistnet
import numpy as np
import matplotlib.pyplot as plt
model = mnistnet(minibatchsize=64, learningrate = 0.01)
model.buildnet()
model.loaddata()
model.init_net()
model.data_mode(1)
model.train_mode(1)
epoch=0
acc = []
loss =[]
weight = []
grad_norm = []
dis =[]
model.lr = 0.1
for jj in range(35):
model.eval_weight()
weight.append(model.v_weight)
model.lr *= 0.99
for ii in range(10000):
model.global_step = 0
model.next_batch()
model.train_net( )
if epoch < model.epoch:
epoch = model.epoch
# model.save_model('exp1')
if (ii+1) % 1000 == 0 :
model.fill_train_data()
model.calloss()
loss.append(model.v_loss)
model.calacc()
acc.append(model.v_acc)
print('epoch',model.epoch,'loss', model.v_loss,'acc',model.v_acc,'lr',model.lr)
model.fill_train_data()
model.eval_grad()
print(model.v_grad_max)
print(model.v_grad_min)
print(model.v_grad_norm)
grad_norm.append(model.v_grad_norm)
#
model.eval_weight()
weight.append(model.v_weight)
#
# dis_1 = np.linalg.norm(weight[-1]-weight[-2])
# dis.append(dis_1)
# print(dis_1 )