当前位置: 首页>>代码示例>>Python>>正文


Python ops._USE_C_API属性代码示例

本文整理汇总了Python中tensorflow.python.framework.ops._USE_C_API属性的典型用法代码示例。如果您正苦于以下问题:Python ops._USE_C_API属性的具体用法?Python ops._USE_C_API怎么用?Python ops._USE_C_API使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在tensorflow.python.framework.ops的用法示例。


在下文中一共展示了ops._USE_C_API属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sort_by_field_invalid_inputs

# 需要导入模块: from tensorflow.python.framework import ops [as 别名]
# 或者: from tensorflow.python.framework.ops import _USE_C_API [as 别名]
def test_sort_by_field_invalid_inputs(self):
    corners = tf.constant([4 * [0.0], 4 * [0.5], 4 * [1.0], 4 * [2.0], 4 *
                           [3.0], 4 * [4.0]])
    misc = tf.constant([[.95, .9], [.5, .3]], tf.float32)
    weights = tf.constant([.1, .2], tf.float32)
    boxes = box_list.BoxList(corners)
    boxes.add_field('misc', misc)
    boxes.add_field('weights', weights)

    with self.test_session() as sess:
      with self.assertRaises(ValueError):
        box_list_ops.sort_by_field(boxes, 'area')

      with self.assertRaises(ValueError):
        box_list_ops.sort_by_field(boxes, 'misc')

      if ops._USE_C_API:
        with self.assertRaises(ValueError):
          box_list_ops.sort_by_field(boxes, 'weights')
      else:
        with self.assertRaisesWithPredicateMatch(errors.InvalidArgumentError,
                                                 'Incorrect field size'):
          sess.run(box_list_ops.sort_by_field(boxes, 'weights').get()) 
开发者ID:ambakick,项目名称:Person-Detection-and-Tracking,代码行数:25,代码来源:box_list_ops_test.py

示例2: _use_c_api_wrapper

# 需要导入模块: from tensorflow.python.framework import ops [as 别名]
# 或者: from tensorflow.python.framework.ops import _USE_C_API [as 别名]
def _use_c_api_wrapper(fn, use_c_api, *args, **kwargs):
  prev_value = ops._USE_C_API
  ops._USE_C_API = use_c_api
  try:
    with ops.Graph().as_default():
      fn(*args, **kwargs)
  finally:
    ops._USE_C_API = prev_value
# pylint: disable=protected-access 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:11,代码来源:test_util.py

示例3: c_api_and_cuda_enabled

# 需要导入模块: from tensorflow.python.framework import ops [as 别名]
# 或者: from tensorflow.python.framework.ops import _USE_C_API [as 别名]
def c_api_and_cuda_enabled():
  return ops._USE_C_API and IsGoogleCudaEnabled() 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:4,代码来源:test_util.py

示例4: _from_definition

# 需要导入模块: from tensorflow.python.framework import ops [as 别名]
# 或者: from tensorflow.python.framework.ops import _USE_C_API [as 别名]
def _from_definition(fdef, grad_func=None):
  """Creates a _DefinedFunction initialized from a FunctionDef proto.

  Args:
    fdef: a FunctionDef
    grad_func: a _DefinedFunction or None

  Returns:
    A _DefinedFunction representing fdef
  """
  # TODO(iga): This method does major surgery on _DefinedFunction.
  # Make it a named constructor using @classmethod of _DefinedFunction.

  # The Python callable is only needed to create a FunctionDef. Since we have
  # the FunctionDef here, we don't need to set _DefinedFunction._func (nor do we
  # have access to such a callable here).
  func = None
  argnames = [arg.name for arg in fdef.signature.input_arg]
  input_types = tuple(
      dtypes.as_dtype(arg.type) for arg in fdef.signature.input_arg)
  func_name = fdef.signature.name
  # Note: FunctionDefs do not include python gradient functions, so if the
  # original _DefinedFunction included one it will not be reflected here.
  python_grad_func = None
  out_names = [arg.name for arg in fdef.signature.output_arg]
  result = _DefinedFunction(func, argnames, input_types, func_name, grad_func,
                            python_grad_func, out_names)
  # pylint: disable=protected-access
  if ops._USE_C_API:
    serialized = fdef.SerializeToString()
    with errors.raise_exception_on_not_ok_status() as status:
      result._c_func = c_api.TF_FunctionImportFunctionDef(serialized, status)
    result._extra_inputs = []
  else:
    result._definition = fdef
    # Captured inputs are added as regular inputs to a function when it's
    # serialized, i.e. any extra inputs from the original function are now
    # included in `result`._args
    result._extra_inputs = []
    result._hash_str = result._create_hash_str(
        result._definition.signature.input_arg,
        result._definition.signature.output_arg, result._definition.node_def)
  # pylint: enable=protected-access

  return result 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:47,代码来源:function.py


注:本文中的tensorflow.python.framework.ops._USE_C_API属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。