本文整理匯總了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'])