当前位置: 首页>>代码示例>>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;未经允许,请勿转载。