本文整理匯總了Python中tensorflow.contrib.graph_editor.select_ops方法的典型用法代碼示例。如果您正苦於以下問題:Python graph_editor.select_ops方法的具體用法?Python graph_editor.select_ops怎麽用?Python graph_editor.select_ops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.contrib.graph_editor
的用法示例。
在下文中一共展示了graph_editor.select_ops方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: capture_ops
# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import select_ops [as 別名]
def capture_ops():
"""Decorator to capture ops created in the block.
with capture_ops() as ops:
# create some ops
print(ops) # => prints ops created.
"""
micros = int(time.time()*10**6)
scope_name = str(micros)
op_list = []
with tf.name_scope(scope_name):
yield op_list
g = tf.get_default_graph()
op_list.extend(ge.select_ops(scope_name+"/.*", graph=g))
示例2: capture_ops
# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import select_ops [as 別名]
def capture_ops():
"""Decorator to capture ops created in the block.
with capture_ops() as ops:
# create some ops
print(ops) # => prints ops created.
"""
micros = int(time.time() * 10**6)
scope_name = str(micros)
op_list = []
with tf.name_scope(scope_name):
yield op_list
g = tf.get_default_graph()
op_list.extend(ge.select_ops(scope_name + "/.*", graph=g))
示例3: test_transform
# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import select_ops [as 別名]
def test_transform(self):
transformer = ge.Transformer()
def my_transform_op_handler(info, op):
add_noise = op.name.startswith("Add")
op_ = ge.transform.copy_op_handler(info, op)
if add_noise:
# add some noise to op
with info.graph_.as_default():
t_ = tf.add(tf.constant(1.0, shape=[10], name="Noise"),
op_.outputs[0], name="AddNoise")
# return the "noisy" op
return t_.op
else:
return op_
transformer.transform_op_handler = my_transform_op_handler
graph = tf.Graph()
transformer(self.graph, graph, "", "")
matcher0 = ge.matcher("AddNoise").input_ops(
"Noise", ge.matcher("Add").input_ops("Const", "Input"))
matcher1 = ge.matcher("AddNoise_1").input_ops(
"Noise_1", ge.matcher("Add_1").input_ops("Const_1", matcher0))
matcher2 = ge.matcher("AddNoise_2").input_ops(
"Noise_2", ge.matcher("Add_2").input_ops("Const_2", matcher1))
top = ge.select_ops("^AddNoise_2$", graph=graph)[0]
self.assertTrue(matcher2(top))
示例4: test_transform_in_place
# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import select_ops [as 別名]
def test_transform_in_place(self):
transformer = ge.Transformer()
def my_transform_op_handler_in_place(info, op):
add_noise = op.name.startswith("Add")
op = ge.transform.transform_op_in_place(info, op,
detach_outputs=add_noise)
if add_noise:
# add some noise to op
with info.graph_.as_default():
t = tf.add(tf.constant(1.0, shape=[10], name="Noise"), op.outputs[0],
name="AddNoise")
# return the "noisy" op
return t.op
else:
return op
transformer.transform_op_handler = my_transform_op_handler_in_place
transformer(self.graph, self.graph, "", "")
matcher0 = ge.matcher("AddNoise").input_ops(
"Noise", ge.matcher("Add").input_ops("Const", "Input"))
matcher1 = ge.matcher("AddNoise_1").input_ops(
"Noise_1", ge.matcher("Add_1").input_ops("Const_1", matcher0))
matcher2 = ge.matcher("AddNoise_2").input_ops(
"Noise_2", ge.matcher("Add_2").input_ops("Const_2", matcher1))
top = ge.select_ops("^AddNoise_2$", graph=self.graph)[0]
self.assertTrue(matcher2(top))
示例5: capture_ops
# 需要導入模塊: from tensorflow.contrib import graph_editor [as 別名]
# 或者: from tensorflow.contrib.graph_editor import select_ops [as 別名]
def capture_ops():
"""Decorator to capture ops created in the block.
with capture_ops() as ops:
# create some ops
print(ops) # => prints ops created.
"""
micros = int(time.time()*10**6)
scope_name = str(micros)
op_list = []
with tf.name_scope(scope_name):
yield op_list
g = tf.get_default_graph()
op_list.extend(ge.select_ops(scope_name+"/.*", graph=g))