本文整理汇总了Python中tensorflow.compat.v1.disable_eager_execution方法的典型用法代码示例。如果您正苦于以下问题:Python v1.disable_eager_execution方法的具体用法?Python v1.disable_eager_execution怎么用?Python v1.disable_eager_execution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.compat.v1
的用法示例。
在下文中一共展示了v1.disable_eager_execution方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import disable_eager_execution [as 别名]
def parse(self, onnx_file, output_nodes=None, model_name=None):
tf.disable_eager_execution()
if model_name:
graph_name = model_name
else:
graph_name, _ = os.path.splitext(
os.path.basename(onnx_file)
)
tf.reset_default_graph()
model = onnx.load(onnx_file)
onnx_graph = model.graph
ugraph = uTensorGraph(
name=graph_name,
output_nodes=[],
lib_name='onnx',
ops_info={},
)
self._build_graph(onnx_graph, ugraph)
ugraph = Legalizer.legalize(ugraph)
tf.reset_default_graph()
return ugraph
示例2: test_parse_events_files
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import disable_eager_execution [as 别名]
def test_parse_events_files(self):
tb_summary_dir = self.create_tempdir()
tf.disable_eager_execution() # Needed in pytest.
summary_writer = tf.summary.FileWriter(tb_summary_dir.full_path)
tags = [
"eval/foo_task/accuracy",
"eval/foo_task/accuracy",
"loss",
]
values = [1., 2., 3.]
steps = [20, 30, 40]
for tag, value, step in zip(tags, values, steps):
summary = tf.Summary()
summary.value.add(tag=tag, simple_value=value)
summary_writer.add_summary(summary, step)
summary_writer.flush()
events = eval_utils.parse_events_files(tb_summary_dir.full_path)
self.assertDictEqual(
events,
{
"eval/foo_task/accuracy": [(20, 1.), (30, 2.)],
"loss": [(40, 3.)],
},
)
示例3: setUpModule
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import disable_eager_execution [as 别名]
def setUpModule():
tf.disable_eager_execution()
示例4: testPCgradNetworkTPU
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import disable_eager_execution [as 别名]
def testPCgradNetworkTPU(self):
tf.reset_default_graph()
tf.disable_eager_execution()
learning_rate = lambda: 0.001
def pcgrad_computation():
x = tf.constant(1., shape=[64, 472, 472, 3])
layers = [
tf.keras.layers.Conv2D(filters=64, kernel_size=3),
tf.keras.layers.Conv2D(filters=32, kernel_size=3, strides=(2, 2)),
tf.keras.layers.Conv2D(filters=32, kernel_size=3, strides=(2, 2)),
tf.keras.layers.Conv2D(filters=32, kernel_size=3, strides=(2, 2)),
tf.keras.layers.Conv2D(filters=32, kernel_size=3, strides=(2, 2)),
]
y = x
for layer in layers:
y = layer(y)
n_tasks = 10
task_loss_0 = tf.reduce_sum(y)
task_losses = [task_loss_0 * (1. + (n / 10.)) for n in range(n_tasks)]
pcgrad_opt = pcgrad.PCGrad(
tf.train.GradientDescentOptimizer(learning_rate))
pcgrad_grads_and_vars = pcgrad_opt.compute_gradients(
task_losses, var_list=tf.trainable_variables())
return pcgrad_opt.apply_gradients(pcgrad_grads_and_vars)
tpu_computation = tf.compat.v1.tpu.batch_parallel(pcgrad_computation,
num_shards=2)
self.evaluate(tf.compat.v1.tpu.initialize_system())
self.evaluate(tf.compat.v1.global_variables_initializer())
self.evaluate(tpu_computation)
self.evaluate(tf.compat.v1.tpu.shutdown_system())