本文整理汇总了Python中tensorflow.contrib.graph_editor.get_forward_walk_ops方法的典型用法代码示例。如果您正苦于以下问题:Python graph_editor.get_forward_walk_ops方法的具体用法?Python graph_editor.get_forward_walk_ops怎么用?Python graph_editor.get_forward_walk_ops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.graph_editor
的用法示例。
在下文中一共展示了graph_editor.get_forward_walk_ops方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tf_toposort
# 需要导入模块: from tensorflow.contrib import graph_editor [as 别名]
# 或者: from tensorflow.contrib.graph_editor import get_forward_walk_ops [as 别名]
def tf_toposort(ts, within_ops=None):
all_ops = ge.get_forward_walk_ops(
[x.op for x in ts], within_ops=within_ops)
deps = {}
for op in all_ops:
for o in op.outputs:
deps[o] = set(op.inputs)
sorted_ts = toposort(deps)
# only keep the tensors from our original list
ts_sorted_lists = []
for l in sorted_ts:
keep = list(set(l).intersection(ts))
if keep:
ts_sorted_lists.append(keep)
return ts_sorted_lists
示例2: tf_toposort
# 需要导入模块: from tensorflow.contrib import graph_editor [as 别名]
# 或者: from tensorflow.contrib.graph_editor import get_forward_walk_ops [as 别名]
def tf_toposort(ts, within_ops=None):
all_ops = ge.get_forward_walk_ops([x.op for x in ts], within_ops=within_ops)
deps = {}
for op in all_ops:
for o in op.outputs:
deps[o] = set(op.inputs)
sorted_ts = toposort(deps)
# only keep the tensors from our original list
ts_sorted_lists = []
for l in sorted_ts:
keep = list(set(l).intersection(ts))
if keep:
ts_sorted_lists.append(keep)
return ts_sorted_lists
示例3: test_resnet_structure
# 需要导入模块: from tensorflow.contrib import graph_editor [as 别名]
# 或者: from tensorflow.contrib.graph_editor import get_forward_walk_ops [as 别名]
def test_resnet_structure():
"""sanity check on TF resnet structure."""
tf.reset_default_graph()
nodes = util.make_resnet(3)
all_ops = ge.get_forward_walk_ops(seed_ops=nodes[0].op)
desired_graph = {0: [1, 2], 1: [2], 2: [3, 4], 3: [4]}
actual_graph = util.tf_ops_to_graph(all_ops)
assert(util.graphs_isomorphic(actual_graph, desired_graph))
示例4: test_articulation_points_resnet
# 需要导入模块: from tensorflow.contrib import graph_editor [as 别名]
# 或者: from tensorflow.contrib.graph_editor import get_forward_walk_ops [as 别名]
def test_articulation_points_resnet():
"""Make sure articulation points are found correctly in resnet."""
tf.reset_default_graph()
nodes = util.make_resnet(3)
all_ops = ge.get_forward_walk_ops(seed_ops=nodes[0].op)
graph = nx.Graph(util.tf_ops_to_graph(all_ops))
assert util.set_equal(util.format_ops(nx.articulation_points(graph)),
['a01_add'])
tf.reset_default_graph()
nodes = util.make_resnet(4)
all_ops = ge.get_forward_walk_ops(seed_ops=nodes[0].op)
graph = nx.Graph(util.tf_ops_to_graph(all_ops))
assert util.set_equal(util.format_ops(nx.articulation_points(graph)),
['a01_add', 'a02_add'])