-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix: Models with shared layers shouldn't be considered Sequential like #8025
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,28 @@ def print_summary(model, line_length=None, positions=None, print_fn=print): | |
sequential_like = True | ||
else: | ||
sequential_like = True | ||
for v in model.nodes_by_depth.values(): | ||
nodes_by_depth = model.nodes_by_depth.values() | ||
nodes = [] | ||
for v in nodes_by_depth: | ||
if (len(v) > 1) or (len(v) == 1 and len(v[0].inbound_layers) > 1): | ||
# if the model has multiple nodes or if the nodes have multiple inbound_layers | ||
# the model is no longer sequential | ||
sequential_like = False | ||
break | ||
nodes += v | ||
if sequential_like: | ||
# search for shared layers | ||
for layer in model.layers: | ||
flag = False | ||
for node in layer.inbound_nodes: | ||
if node in nodes: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this always be True? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily. A layer might be shared between 2 models and hence have more than one inbound node. But we are looking for layers which are being shared within the same model. The inbound nodes should be part of the graph of the model for which we are printing the summary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dense = Dense(10)
a = Input((10,))
b = dense(a)
model1 = Model(a, b)
a2 = Input((10,))
b2 = dense(a2)
model2 = Model(a2, b2)
model1.summary()
# Here dense layer has 2 inbound nodes,
#but the second node is not part of model1.
# So should be considered sequential like |
||
if flag: | ||
sequential_like = False | ||
break | ||
else: | ||
flag = True | ||
if not sequential_like: | ||
break | ||
|
||
if sequential_like: | ||
line_length = line_length or 65 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the criteria you use for shared layers. A comment here would help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A layer is shared in a model if it has 2 or more inbound nodes and those inbound nodes are part of the graph.