當前位置: 首頁>>代碼示例>>Python>>正文


Python v1.disable_eager_execution方法代碼示例

本文整理匯總了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 
開發者ID:uTensor,項目名稱:utensor_cgen,代碼行數:23,代碼來源:onnx.py

示例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.)],
        },
    ) 
開發者ID:google-research,項目名稱:text-to-text-transfer-transformer,代碼行數:26,代碼來源:eval_utils_test.py

示例3: setUpModule

# 需要導入模塊: from tensorflow.compat import v1 [as 別名]
# 或者: from tensorflow.compat.v1 import disable_eager_execution [as 別名]
def setUpModule():
  tf.disable_eager_execution() 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:4,代碼來源:resnet_v2_test.py

示例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()) 
開發者ID:google-research,項目名稱:tensor2robot,代碼行數:34,代碼來源:pcgrad_tpu_test.py


注:本文中的tensorflow.compat.v1.disable_eager_execution方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。