-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.py
28 lines (26 loc) · 1.07 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
import numpy as np
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
# 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)
if (type(layer) == Dropout):
descriptors.append(layer.rate)
result.append(descriptors)
return result