-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_view_8L_randomwaves.py
76 lines (66 loc) · 2.06 KB
/
run_view_8L_randomwaves.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
import numpy as np
import scipy.io as sio
import os
import copy
from keras.callbacks import EarlyStopping
from keras import Model
import prep_four_groups as pfg
import sys
sys.path.append('/home/realtime/project_deep/python')
sys.path.append('/home/realtime/project_deep/python/encoders')
sys.path.append('/home/realtime/project_deep/python/encoders/old')
sys.path.append('/home/realtime/project_deep/python/keras-visualize-activations')
import encoder_8L_0DS
import encoder_8L_1DS
import encoder_8L_2DS
import low_res_encoder as lre
import read_activations
import time
from keras import backend as K
start = time.time()
all_slcs = pfg.get_four_groups_slices()
#encoders = [lre.get_lr_encoder()]
# encoder_8L_0DS.get_encoder(),
# encoder_8L_1DS.get_encoder(),
# encoder_8L_2DS.get_encoder()]
#labels = ["test"]
encoders = [encoder_8L_0DS.get_encoder(),
encoder_8L_1DS.get_encoder(),
encoder_8L_2DS.get_encoder()]
labels = ["E8_0", "E8_1", "E8_2"];
predictions = {'orig':all_slcs}
preds=[]
activation_views = {}
NUM_FILTS = 64
img_width = all_slcs.shape[1]
img_height = all_slcs.shape[2]
for enc in range(len(encoders)):
encoder = encoders[enc];
encoder.summary()
encoder.fit(all_slcs, all_slcs,
epochs=50,
#epochs=2,
batch_size=128,
shuffle=True,
validation_split=0.3,
callbacks=[EarlyStopping(patience=2)])
encoder_filename = labels[enc] + '.h5'
encoder.save(encoder_filename)
preds.append(encoder.predict(all_slcs))
predictions.update({labels[enc]:preds[enc]})
sio.savemat('predictions.mat', predictions)
actviews = read_activations.get_activations(encoder, all_slcs[1:10,:,:], True))
acts = []
for i in range(len(actviews)):
#acts.append(np.squeeze(actviews[i][:,:,:,0]))
#int(len(acts))
lab = labels[enc] + '_' + str(i)
#activation_views.update({lab:acts})
actview = actviews[i]
activation_views.update({lab:actview})
#sio.savemat(lab + '.mat', activation_views)
#activation_views.update({lab:acts})
sio.savemat('activation_views.mat', activation_views)
end = time.time()
print("elapsed time (hrs):")
print((end-start)/(60*60))