-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
46 lines (41 loc) · 1.77 KB
/
test_utils.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
from termcolor import colored
from tensorflow.keras.layers import Input
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Conv2DTranspose
from tensorflow.keras.layers import concatenate
from tensorflow.keras.layers import ZeroPadding2D
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
from tensorflow.keras.layers import RepeatVector
# extracts the description of a given model
def summary(model):
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
result = []
for layer in model.layers:
descriptors = [layer.__class__.__name__, layer.output_shape, layer.count_params()]
if (type(layer) == Conv2D):
descriptors.append(layer.padding)
descriptors.append(layer.activation.__name__)
descriptors.append(layer.kernel_initializer.__class__.__name__)
if (type(layer) == MaxPooling2D):
descriptors.append(layer.pool_size)
descriptors.append(layer.strides)
descriptors.append(layer.padding)
if (type(layer) == Dropout):
descriptors.append(layer.rate)
if (type(layer) == ZeroPadding2D):
descriptors.append(layer.padding)
if (type(layer) == Dense):
descriptors.append(layer.activation.__name__)
if (type(layer) == LSTM):
descriptors.append(layer.input_shape)
descriptors.append(layer.activation.__name__)
descriptors.append(layer.return_sequences)
if (type(layer) == RepeatVector):
descriptors.append(layer.n)
result.append(descriptors)
return result