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


Python check_ops.assert_non_negative方法代碼示例

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


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

示例1: _assert_non_negative_int32_scalar

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _assert_non_negative_int32_scalar(self, x):
    """Helper which ensures that input is a non-negative, int32, scalar."""
    x = ops.convert_to_tensor(x, name="x")
    if x.dtype.base_dtype != dtypes.int32.base_dtype:
      raise TypeError("%s.dtype=%s is not %s" % (x.name, x.dtype, dtypes.int32))
    x_value_static = tensor_util.constant_value(x)
    if x.get_shape().ndims is not None and x_value_static is not None:
      if x.get_shape().ndims != 0:
        raise ValueError("%s.ndims=%d is not 0 (scalar)" %
                         (x.name, x.get_shape().ndims))
      if x_value_static < 0:
        raise ValueError("%s.value=%d cannot be negative" %
                         (x.name, x_value_static))
      return x
    if self.validate_args:
      x = control_flow_ops.with_dependencies([
          check_ops.assert_rank(x, 0),
          check_ops.assert_non_negative(x)], x)
    return x 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:21,代碼來源:shape.py

示例2: embed_check_nonnegative_integer_form

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def embed_check_nonnegative_integer_form(
    x, name="embed_check_nonnegative_integer_form"):
  """Assert x is a non-negative tensor, and optionally of integers."""
  with ops.name_scope(name, values=[x]):
    x = ops.convert_to_tensor(x, name="x")
    assertions = [
        check_ops.assert_non_negative(
            x, message="'{}' must be non-negative.".format(x.op.name)),
    ]
    if not x.dtype.is_integer:
      assertions += [
          assert_integer_form(
              x, message="'{}' cannot contain fractional components.".format(
                  x.op.name)),
      ]
    return control_flow_ops.with_dependencies(assertions, x) 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:18,代碼來源:util.py

示例3: _maybe_assert_valid_total_count

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _maybe_assert_valid_total_count(self, total_count, validate_args):
    if not validate_args:
      return total_count
    return control_flow_ops.with_dependencies([
        check_ops.assert_non_negative(
            total_count,
            message="total_count must be non-negative."),
        distribution_util.assert_integer_form(
            total_count,
            message="total_count cannot contain fractional values."),
    ], total_count) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:multinomial.py

示例4: embed_check_nonnegative_discrete

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def embed_check_nonnegative_discrete(x, check_integer=True):
  """Assert x is a non-negative tensor, and optionally of integers."""
  assertions = [check_ops.assert_non_negative(
      x, message="x must be non-negative.")]
  if check_integer:
    assertions += [assert_integer_form(
        x, message="x cannot contain fractional components.")]
  return control_flow_ops.with_dependencies(assertions, x) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:util.py

示例5: _maybe_assert_valid_sample

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _maybe_assert_valid_sample(self, counts):
    """Check counts for proper shape, values, then return tensor version."""
    if not self.validate_args:
      return counts
    return control_flow_ops.with_dependencies([
        check_ops.assert_non_negative(
            counts,
            message="counts must be non-negative."),
        check_ops.assert_equal(
            self.total_count, math_ops.reduce_sum(counts, -1),
            message="counts last-dimension must sum to `self.total_count`"),
        distribution_util.assert_integer_form(
            counts,
            message="counts cannot contain fractional components."),
    ], counts) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:17,代碼來源:dirichlet_multinomial.py

示例6: get_sample_ndims

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def get_sample_ndims(self, x, name="get_sample_ndims"):
    """Returns number of dimensions corresponding to iid draws ("sample").

    Args:
      x: `Tensor`.
      name: Python `str`. The name to give this op.

    Returns:
      sample_ndims: `Tensor` (0D, `int32`).

    Raises:
      ValueError: if `sample_ndims` is calculated to be negative.
    """
    with self._name_scope(name, values=[x]):
      ndims = self.get_ndims(x, name=name)
      if self._is_all_constant_helper(ndims, self.batch_ndims,
                                      self.event_ndims):
        ndims = tensor_util.constant_value(ndims)
        sample_ndims = (ndims - self._batch_ndims_static -
                        self._event_ndims_static)
        if sample_ndims < 0:
          raise ValueError(
              "expected batch_ndims(%d) + event_ndims(%d) <= ndims(%d)" %
              (self._batch_ndims_static, self._event_ndims_static, ndims))
        return ops.convert_to_tensor(sample_ndims, name="sample_ndims")
      else:
        with ops.name_scope(name="sample_ndims"):
          sample_ndims = ndims - self.batch_ndims - self.event_ndims
          if self.validate_args:
            sample_ndims = control_flow_ops.with_dependencies(
                [check_ops.assert_non_negative(sample_ndims)], sample_ndims)
        return sample_ndims 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:34,代碼來源:shape.py

示例7: _get_tol

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _get_tol(self, tol):
    if tol is None:
      return ops.convert_to_tensor(0, dtype=self.loc.dtype)

    tol = ops.convert_to_tensor(tol, dtype=self.loc.dtype)
    if self.validate_args:
      tol = control_flow_ops.with_dependencies([
          check_ops.assert_non_negative(
              tol, message="Argument 'tol' must be non-negative")
      ], tol)
    return tol 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:deterministic.py

示例8: _maybe_assert_valid_x

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _maybe_assert_valid_x(self, x):
    if not self.validate_args or self.power == 0.:
      return x
    is_valid = check_ops.assert_non_negative(
        1. + self.power * x,
        message="Forward transformation input must be at least {}.".format(
            -1. / self.power))
    return control_flow_ops.with_dependencies([is_valid], x) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:power_transform_impl.py

示例9: _maybe_assert_valid_total_count

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _maybe_assert_valid_total_count(self, total_count, validate_args):
    if not validate_args:
      return total_count
    return control_flow_ops.with_dependencies([
        check_ops.assert_non_negative(
            total_count,
            message="total_count must be non-negative."),
        distribution_util.assert_integer_form(
            total_count,
            message="total_count cannot contain fractional componentes."),
    ], total_count) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:binomial.py

示例10: _check_num_rows_possibly_add_asserts

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _check_num_rows_possibly_add_asserts(self):
    """Static check of init arg `num_rows`, possibly add asserts."""
    # Possibly add asserts.
    if self._assert_proper_shapes:
      self._num_rows = control_flow_ops.with_dependencies(
          [
              check_ops.assert_rank(
                  self._num_rows,
                  0,
                  message="Argument num_rows must be a 0-D Tensor."),
              check_ops.assert_non_negative(
                  self._num_rows,
                  message="Argument num_rows must be non-negative."),
          ],
          self._num_rows)

    # Static checks.
    if not self._num_rows.dtype.is_integer:
      raise TypeError("Argument num_rows must be integer type.  Found:"
                      " %s" % self._num_rows)

    num_rows_static = self._num_rows_static

    if num_rows_static is None:
      return  # Cannot do any other static checks.

    if num_rows_static.ndim != 0:
      raise ValueError("Argument num_rows must be a 0-D Tensor.  Found:"
                       " %s" % num_rows_static)

    if num_rows_static < 0:
      raise ValueError("Argument num_rows must be non-negative.  Found:"
                       " %s" % num_rows_static) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:35,代碼來源:linear_operator_identity.py

示例11: _check_batch_shape_possibly_add_asserts

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _check_batch_shape_possibly_add_asserts(self):
    """Static check of init arg `batch_shape`, possibly add asserts."""
    if self._batch_shape_arg is None:
      return

    # Possibly add asserts
    if self._assert_proper_shapes:
      self._batch_shape_arg = control_flow_ops.with_dependencies(
          [
              check_ops.assert_rank(
                  self._batch_shape_arg,
                  1,
                  message="Argument batch_shape must be a 1-D Tensor."),
              check_ops.assert_non_negative(
                  self._batch_shape_arg,
                  message="Argument batch_shape must be non-negative."),
          ],
          self._batch_shape_arg)

    # Static checks
    if not self._batch_shape_arg.dtype.is_integer:
      raise TypeError("Argument batch_shape must be integer type.  Found:"
                      " %s" % self._batch_shape_arg)

    if self._batch_shape_static is None:
      return  # Cannot do any other static checks.

    if self._batch_shape_static.ndim != 1:
      raise ValueError("Argument batch_shape must be a 1-D Tensor.  Found:"
                       " %s" % self._batch_shape_static)

    if np.any(self._batch_shape_static < 0):
      raise ValueError("Argument batch_shape must be non-negative.  Found:"
                       "%s" % self._batch_shape_static) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:36,代碼來源:linear_operator_identity.py

示例12: _assert_valid_sample

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _assert_valid_sample(self, counts):
    """Check counts for proper shape, values, then return tensor version."""
    if not self.validate_args: return counts
    return control_flow_ops.with_dependencies([
        check_ops.assert_non_negative(
            counts, message="counts has negative components."),
        check_ops.assert_equal(
            self.n, math_ops.reduce_sum(counts, reduction_indices=[-1]),
            message="counts do not sum to n."),
        distribution_util.assert_integer_form(
            counts, message="counts have non-integer components.")
    ], counts) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:14,代碼來源:multinomial.py

示例13: _assert_valid_counts

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _assert_valid_counts(self, counts):
    """Check counts for proper shape, values, then return tensor version."""
    counts = ops.convert_to_tensor(counts, name="counts")
    if not self.validate_args:
      return counts
    candidate_n = math_ops.reduce_sum(counts, reduction_indices=[-1])
    return control_flow_ops.with_dependencies([
        check_ops.assert_non_negative(counts),
        check_ops.assert_equal(
            self._n, candidate_n,
            message="counts do not sum to n"),
        distribution_util.assert_integer_form(counts)], counts) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:14,代碼來源:dirichlet_multinomial.py

示例14: _assert_valid_n

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def _assert_valid_n(self, n, validate_args):
    n = ops.convert_to_tensor(n, name="n")
    if not validate_args:
      return n
    return control_flow_ops.with_dependencies(
        [check_ops.assert_non_negative(n),
         distribution_util.assert_integer_form(n)], n) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:9,代碼來源:dirichlet_multinomial.py

示例15: get_sample_ndims

# 需要導入模塊: from tensorflow.python.ops import check_ops [as 別名]
# 或者: from tensorflow.python.ops.check_ops import assert_non_negative [as 別名]
def get_sample_ndims(self, x, name="get_sample_ndims"):
    """Returns number of dimensions corresponding to iid draws ("sample").

    Args:
      x: `Tensor`.
      name: `String`. The name to give this op.

    Returns:
      sample_ndims: `Tensor` (0D, `int32`).

    Raises:
      ValueError: if `sample_ndims` is calculated to be negative.
    """
    with self._name_scope(name, values=[x]):
      ndims = self.get_ndims(x, name=name)
      if self._is_all_constant_helper(ndims, self.batch_ndims,
                                      self.event_ndims):
        ndims = tensor_util.constant_value(ndims)
        sample_ndims = (ndims - self._batch_ndims_static -
                        self._event_ndims_static)
        if sample_ndims < 0:
          raise ValueError(
              "expected batch_ndims(%d) + event_ndims(%d) <= ndims(%d)" %
              (self._batch_ndims_static, self._event_ndims_static, ndims))
        return ops.convert_to_tensor(sample_ndims, name="sample_ndims")
      else:
        with ops.name_scope(name="sample_ndims"):
          sample_ndims = ndims - self.batch_ndims - self.event_ndims
          if self.validate_args:
            sample_ndims = control_flow_ops.with_dependencies(
                [check_ops.assert_non_negative(sample_ndims)], sample_ndims)
        return sample_ndims 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:34,代碼來源:shape.py


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