From ad49962ba984536599770277aaf55211faa95014 Mon Sep 17 00:00:00 2001 From: Philip Bachman Date: Thu, 21 Apr 2016 00:38:23 -0400 Subject: [PATCH] fix layer/node topo sort problem (#2433) * fix layer/node topo sort problem * fix to only iterate over valid layer/node keys --- keras/engine/topology.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keras/engine/topology.py b/keras/engine/topology.py index 1d2330bdc50..540c8a2ebef 100644 --- a/keras/engine/topology.py +++ b/keras/engine/topology.py @@ -1672,7 +1672,8 @@ def build_map_of_graph(tensor, seen_nodes=set(), depth=0, layers_by_depth[depth] = [] layers_by_depth[depth].append(layer) - depth_keys = list(nodes_by_depth.keys()) + # get sorted list of layer depths + depth_keys = list(layers_by_depth.keys()) depth_keys.sort(reverse=True) # set self.layers and self.layers_by_depth @@ -1686,6 +1687,10 @@ def build_map_of_graph(tensor, seen_nodes=set(), depth=0, self.layers = layers self.layers_by_depth = layers_by_depth + # get sorted list of node depths + depth_keys = list(nodes_by_depth.keys()) + depth_keys.sort(reverse=True) + # check that all tensors required are computable. # computable_tensors: all tensors in the graph # that can be computed from the inputs provided