Refactored model.summary and fixed tests
@@ -165,26 +165,6 @@ def print_summary(model,
if not sequential_like:
break
- if show_trainable:
- # Add trainable column
- if sequential_like:
- line_length = line_length or 85
- positions = positions or [.33, .70, .89, 1.]
- if positions[-1] <= 1:
- positions = [int(line_length * p) for p in positions]
- # header names for the different log elements
- to_display = ['Layer (type)', 'Output Shape', 'Param #', 'Trainable']
- else:
- line_length = line_length or 110
- positions = positions or [.33, .40, .55, .67, 1.]
- if positions[-1] <= 1:
- positions = [int(line_length * p) for p in positions]
- # header names for the different log elements
- to_display = ['Layer (type)', 'Output Shape', 'Param #', 'Trainable', 'Connected to']
- relevant_nodes = []
- for v in model._nodes_by_depth.values():
- relevant_nodes += v
- else:
if sequential_like:
line_length = line_length or 65
positions = positions or [.45, .85, 1.]
@@ -203,6 +183,11 @@ def print_summary(model,
for v in model._nodes_by_depth.values():
relevant_nodes += v
+ if show_trainable:
+ line_length += 11
+ positions.append(line_length)
+ to_display.append("Trainable")
+
def print_row(fields, positions, nested_level=0):
left_to_print = [str(x) for x in fields]
while any(left_to_print):
@@ -271,11 +256,10 @@ def print_summary(model,
params = '0 (unused)'
else:
params = layer.count_params()
+ fields = [name + ' (' + cls_name + ')', output_shape, params]
if show_trainable:
- fields = [name + ' (' + cls_name + ')', output_shape, params, "T" if layer.trainable else "F"]
- else:
- fields = [name + ' (' + cls_name + ')', output_shape, params]
+ fields.append("Y" if layer.trainable else "N")
print_row(fields, positions, nested_level)
@@ -303,18 +287,14 @@ def print_summary(model,
name = layer.name
cls_name = layer.__class__.__name__
- if show_trainable:
- fields = [
- name + ' (' + cls_name + ')', output_shape,
- layer.count_params(),
- "T" if layer.trainable else "F",
- connections
- ]
- else:
fields = [
name + ' (' + cls_name + ')', output_shape,
layer.count_params(), connections
]
+
+ if show_trainable:
+ fields.append("Y" if layer.trainable else "N")
+
print_row(fields, positions, nested_level)
def print_layer(layer, nested_level=0, is_nested_last=False):
