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


Python tpu.rewrite方法代碼示例

本文整理匯總了Python中tensorflow.contrib.tpu.rewrite方法的典型用法代碼示例。如果您正苦於以下問題:Python tpu.rewrite方法的具體用法?Python tpu.rewrite怎麽用?Python tpu.rewrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.tpu的用法示例。


在下文中一共展示了tpu.rewrite方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: execute_tpu

# 需要導入模塊: from tensorflow.contrib import tpu [as 別名]
# 或者: from tensorflow.contrib.tpu import rewrite [as 別名]
def execute_tpu(self, graph_fn, inputs):
    """Constructs the graph, executes it on TPU and returns the result.

    Args:
      graph_fn: a callable that constructs the tensorflow graph to test. The
        arguments of this function should correspond to `inputs`.
      inputs: a list of numpy arrays to feed input to the computation graph.

    Returns:
      A list of numpy arrays or a scalar returned from executing the tensorflow
      graph.
    """
    with self.test_session(graph=tf.Graph()) as sess:
      placeholders = [tf.placeholder_with_default(v, v.shape) for v in inputs]
      tpu_computation = tpu.rewrite(graph_fn, placeholders)
      sess.run(tpu.initialize_system())
      sess.run([tf.global_variables_initializer(), tf.tables_initializer(),
                tf.local_variables_initializer()])
      materialized_results = sess.run(tpu_computation,
                                      feed_dict=dict(zip(placeholders, inputs)))
      sess.run(tpu.shutdown_system())
      if len(materialized_results) == 1:
        materialized_results = materialized_results[0]
    return materialized_results 
開發者ID:ShreyAmbesh,項目名稱:Traffic-Rule-Violation-Detection-System,代碼行數:26,代碼來源:test_case.py

示例2: execute_tpu

# 需要導入模塊: from tensorflow.contrib import tpu [as 別名]
# 或者: from tensorflow.contrib.tpu import rewrite [as 別名]
def execute_tpu(self, graph_fn, inputs):
    """Constructs the graph, executes it on TPU and returns the result.

    Args:
      graph_fn: a callable that constructs the tensorflow graph to test. The
        arguments of this function should correspond to `inputs`.
      inputs: a list of numpy arrays to feed input to the computation graph.

    Returns:
      A list of numpy arrays or a scalar returned from executing the tensorflow
      graph.
    """
    with self.test_session(graph=tf.Graph()) as sess:
      placeholders = [tf.placeholder_with_default(v, v.shape) for v in inputs]
      tpu_computation = tpu.rewrite(graph_fn, placeholders)
      sess.run(tpu.initialize_system())
      sess.run([tf.global_variables_initializer(), tf.tables_initializer(),
                tf.local_variables_initializer()])
      materialized_results = sess.run(tpu_computation,
                                      feed_dict=dict(zip(placeholders, inputs)))
      sess.run(tpu.shutdown_system())
      if (hasattr(materialized_results, '__len__') and
          len(materialized_results) == 1 and
          (isinstance(materialized_results, list) or
           isinstance(materialized_results, tuple))):
        materialized_results = materialized_results[0]
    return materialized_results 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:29,代碼來源:test_case.py

示例3: execute_tpu

# 需要導入模塊: from tensorflow.contrib import tpu [as 別名]
# 或者: from tensorflow.contrib.tpu import rewrite [as 別名]
def execute_tpu(self, graph_fn, inputs):
    """Constructs the graph, executes it on TPU and returns the result.

    Args:
      graph_fn: a callable that constructs the tensorflow graph to test. The
        arguments of this function should correspond to `inputs`.
      inputs: a list of numpy arrays to feed input to the computation graph.

    Returns:
      A list of numpy arrays or a scalar returned from executing the tensorflow
      graph.
    """
    with self.test_session(graph=tf.Graph()) as sess:
      placeholders = [tf.placeholder_with_default(v, v.shape) for v in inputs]
      tpu_computation = tpu.rewrite(graph_fn, placeholders)
      sess.run(tpu.initialize_system())
      sess.run([tf.global_variables_initializer(), tf.tables_initializer(),
                tf.local_variables_initializer()])
      materialized_results = sess.run(tpu_computation,
                                      feed_dict=dict(zip(placeholders, inputs)))
      sess.run(tpu.shutdown_system())
      if (len(materialized_results) == 1
          and (isinstance(materialized_results, list)
               or isinstance(materialized_results, tuple))):
        materialized_results = materialized_results[0]
    return materialized_results 
開發者ID:cagbal,項目名稱:ros_people_object_detection_tensorflow,代碼行數:28,代碼來源:test_case.py

示例4: execute_tpu

# 需要導入模塊: from tensorflow.contrib import tpu [as 別名]
# 或者: from tensorflow.contrib.tpu import rewrite [as 別名]
def execute_tpu(self, graph_fn, inputs):
        """Constructs the graph, executes it on TPU and returns the result.

        Args:
          graph_fn: a callable that constructs the tensorflow graph to test. The
            arguments of this function should correspond to `inputs`.
          inputs: a list of numpy arrays to feed input to the computation graph.

        Returns:
          A list of numpy arrays or a scalar returned from executing the tensorflow
          graph.
        """
        with self.test_session(graph=tf.Graph()) as sess:
            placeholders = [tf.placeholder_with_default(v, v.shape) for v in inputs]
            tpu_computation = tpu.rewrite(graph_fn, placeholders)
            sess.run(tpu.initialize_system())
            sess.run([tf.global_variables_initializer(), tf.tables_initializer(),
                      tf.local_variables_initializer()])
            materialized_results = sess.run(tpu_computation,
                                            feed_dict=dict(zip(placeholders, inputs)))
            sess.run(tpu.shutdown_system())
            if (len(materialized_results) == 1
                and (isinstance(materialized_results, list)
                     or isinstance(materialized_results, tuple))):
                materialized_results = materialized_results[0]
        return materialized_results 
開發者ID:kujason,項目名稱:monopsr,代碼行數:28,代碼來源:test_case.py

示例5: execute_tpu

# 需要導入模塊: from tensorflow.contrib import tpu [as 別名]
# 或者: from tensorflow.contrib.tpu import rewrite [as 別名]
def execute_tpu(self, graph_fn, inputs):
    """Constructs the graph, executes it on TPU and returns the result.

    Args:
      graph_fn: a callable that constructs the tensorflow graph to test. The
        arguments of this function should correspond to `inputs`.
      inputs: a list of numpy arrays to feed input to the computation graph.

    Returns:
      A list of numpy arrays or a scalar returned from executing the tensorflow
      graph.
    """
    with self.test_session(graph=tf.Graph()) as sess:
      placeholders = [tf.placeholder_with_default(v, v.shape) for v in inputs]
      tpu_computation = tpu.rewrite(graph_fn, placeholders)
      sess.run(tpu.initialize_system())
      sess.run([tf.global_variables_initializer(), tf.tables_initializer(),
                tf.local_variables_initializer()])
      materialized_results = sess.run(tpu_computation,
                                      feed_dict=dict(list(zip(placeholders, inputs))))
      sess.run(tpu.shutdown_system())
      if (len(materialized_results) == 1
          and (isinstance(materialized_results, list)
               or isinstance(materialized_results, tuple))):
        materialized_results = materialized_results[0]
    return materialized_results 
開發者ID:minerva-ml,項目名稱:open-solution-googleai-object-detection,代碼行數:28,代碼來源:test_case.py


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