當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。