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


Python check_ops.assert_positive方法代码示例

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


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

示例1: _check_chol

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _check_chol(self, chol):
    """Verify that `chol` is proper."""
    chol = ops.convert_to_tensor(chol, name="chol")
    if not self.verify_pd:
      return chol

    shape = array_ops.shape(chol)
    rank = array_ops.rank(chol)

    is_matrix = check_ops.assert_rank_at_least(chol, 2)
    is_square = check_ops.assert_equal(
        array_ops.gather(shape, rank - 2), array_ops.gather(shape, rank - 1))

    deps = [is_matrix, is_square]
    diag = array_ops.matrix_diag_part(chol)
    deps.append(check_ops.assert_positive(diag))

    return control_flow_ops.with_dependencies(deps, chol) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:operator_pd_cholesky.py

示例2: _Check3DImage

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _Check3DImage(image, require_static=True):
    """Assert that we are working with properly shaped image.
    Args:
      image: 3-D Tensor of shape [height, width, channels]
        require_static: If `True`, requires that all dimensions of `image` are
        known and non-zero.
    Raises:
      ValueError: if `image.shape` is not a 3-vector.
    Returns:
      An empty list, if `image` has fully defined dimensions. Otherwise, a list
        containing an assert op is returned.
    """
    try:
        image_shape = image.get_shape().with_rank(3)
    except ValueError:
        raise ValueError("'image' must be three-dimensional.")
    if require_static and not image_shape.is_fully_defined():
        raise ValueError("'image' must be fully defined.")
    if any(x == 0 for x in image_shape):
        raise ValueError("all dims of 'image.shape' must be > 0: %s" %
                         image_shape)
    if not image_shape.is_fully_defined():
        return [check_ops.assert_positive(array_ops.shape(image),
                                          ["all dims of 'image.shape' "
                                           "must be > 0."])]
    else:
        return [] 
开发者ID:dengdan,项目名称:seglink,代码行数:29,代码来源:tf_image.py

示例3: _Check3DImage

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _Check3DImage(image, require_static=True):
  """Assert that we are working with properly shaped image.

  Args:
    image: 3-D Tensor of shape [height, width, channels]
    require_static: If `True`, requires that all dimensions of `image` are
      known and non-zero.

  Raises:
    ValueError: if `image.shape` is not a 3-vector.

  Returns:
    An empty list, if `image` has fully defined dimensions. Otherwise, a list
    containing an assert op is returned.
  """
  try:
    image_shape = image.get_shape().with_rank(3)
  except ValueError:
    raise ValueError("'image' (shape %s) must be three-dimensional." %
                     image.shape)
  if require_static and not image_shape.is_fully_defined():
    raise ValueError("'image' (shape %s) must be fully defined." %
                     image_shape)
  if any(x == 0 for x in image_shape):
    raise ValueError("all dims of 'image.shape' must be > 0: %s" %
                     image_shape)
  if not image_shape.is_fully_defined():
    return [check_ops.assert_positive(array_ops.shape(image),
                                      ["all dims of 'image.shape' "
                                       "must be > 0."])]
  else:
    return [] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:34,代码来源:image_ops_impl.py

示例4: _CheckAtLeast3DImage

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _CheckAtLeast3DImage(image, require_static=True):
  """Assert that we are working with properly shaped image.

  Args:
    image: >= 3-D Tensor of size [*, height, width, depth]
    require_static: If `True`, requires that all dimensions of `image` are
      known and non-zero.

  Raises:
    ValueError: if image.shape is not a [>= 3] vector.

  Returns:
    An empty list, if `image` has fully defined dimensions. Otherwise, a list
    containing an assert op is returned.
  """
  try:
    if image.get_shape().ndims is None:
      image_shape = image.get_shape().with_rank(3)
    else:
      image_shape = image.get_shape().with_rank_at_least(3)
  except ValueError:
    raise ValueError("'image' must be at least three-dimensional.")
  if require_static and not image_shape.is_fully_defined():
    raise ValueError('\'image\' must be fully defined.')
  if any(x == 0 for x in image_shape):
    raise ValueError('all dims of \'image.shape\' must be > 0: %s' %
                     image_shape)
  if not image_shape.is_fully_defined():
    return [check_ops.assert_positive(array_ops.shape(image),
                                      ["all dims of 'image.shape' "
                                       "must be > 0."])]
  else:
    return [] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:35,代码来源:image_ops_impl.py

示例5: _maybe_assert_valid_sample

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_assert_valid_sample(self, x):
    check_ops.assert_same_float_dtype(tensors=[x], dtype=self.dtype)
    if not self.validate_args:
      return x
    return control_flow_ops.with_dependencies([
        check_ops.assert_positive(x),
    ], x) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:gamma.py

示例6: _maybe_assert_valid_concentration

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_assert_valid_concentration(self, concentration, validate_args):
    """Checks the validity of the concentration parameter."""
    if not validate_args:
      return concentration
    return control_flow_ops.with_dependencies([
        check_ops.assert_positive(
            concentration,
            message="Concentration parameter must be positive."),
        check_ops.assert_rank_at_least(
            concentration, 1,
            message="Concentration parameter must have >=1 dimensions."),
        check_ops.assert_less(
            1, array_ops.shape(concentration)[-1],
            message="Concentration parameter must have event_size >= 2."),
    ], concentration) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:17,代码来源:dirichlet_multinomial.py

示例7: _maybe_assert_valid_sample

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_assert_valid_sample(self, x):
    """Checks the validity of a sample."""
    if not self.validate_args:
      return x
    return control_flow_ops.with_dependencies([
        check_ops.assert_positive(
            x,
            message="sample must be positive"),
        check_ops.assert_less(
            x, array_ops.ones([], self.dtype),
            message="sample must be no larger than `1`."),
    ], x) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:beta.py

示例8: _maybe_assert_valid_sample

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_assert_valid_sample(self, x):
    """Checks the validity of a sample."""
    if not self.validate_args:
      return x
    return control_flow_ops.with_dependencies([
        check_ops.assert_positive(
            x,
            message="samples must be positive"),
        distribution_util.assert_close(
            array_ops.ones([], dtype=self.dtype),
            math_ops.reduce_sum(x, -1),
            message="sample last-dimension must sum to `1`"),
    ], x) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:dirichlet.py

示例9: _maybe_mask_score

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_mask_score(score, memory_sequence_length, score_mask_value):
  if memory_sequence_length is None:
    return score
  message = ("All values in memory_sequence_length must greater than zero.")
  with ops.control_dependencies(
      [check_ops.assert_positive(memory_sequence_length, message=message)]):
    score_mask = array_ops.sequence_mask(
        memory_sequence_length, maxlen=array_ops.shape(score)[1])
    score_mask_values = score_mask_value * array_ops.ones_like(score)
    return array_ops.where(score_mask, score, score_mask_values) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:attention_wrapper.py

示例10: _check_scale

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _check_scale(self, scale, dtype):
    """Check that the init arg `scale` defines a valid operator."""
    if scale is None:
      return constant_op.constant(1.0, dtype=dtype)

    scale = ops.convert_to_tensor(scale, dtype=dtype, name="scale")

    if not self._verify_pd:
      return scale

    # Further check that this is a rank 0, positive tensor.
    scale = check_ops.assert_scalar(scale)
    return control_flow_ops.with_dependencies(
        [check_ops.assert_positive(scale)], scale) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:16,代码来源:operator_pd_identity.py

示例11: _maybe_assert_valid_sample

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_assert_valid_sample(self, x):
    check_ops.assert_same_float_dtype(
        tensors=[x], dtype=self.dtype)
    if not self.validate_args:
      return x
    return control_flow_ops.with_dependencies([
        check_ops.assert_positive(x),
    ], x) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:10,代码来源:inverse_gamma.py

示例12: __init__

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def __init__(self,
               rate,
               validate_args=False,
               allow_nan_stats=True,
               name="Poisson"):
    """Initialize a batch of Poisson distributions.

    Args:
      rate: Floating point tensor, the rate parameter of the
        distribution(s). `rate` must be positive.
      validate_args: Python `bool`, default `False`. When `True` distribution
        parameters are checked for validity despite possibly degrading runtime
        performance. When `False` invalid inputs may silently render incorrect
        outputs.
      allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
        (e.g., mean, mode, variance) use the value "`NaN`" to indicate the
        result is undefined. When `False`, an exception is raised if one or
        more of the statistic's batch members are undefined.
      name: Python `str` name prefixed to Ops created by this class.
    """
    parameters = locals()
    with ops.name_scope(name, values=[rate]):
      with ops.control_dependencies([check_ops.assert_positive(rate)] if
                                    validate_args else []):
        self._rate = array_ops.identity(rate, name="rate")
    super(Poisson, self).__init__(
        dtype=self._rate.dtype,
        reparameterization_type=distribution.NOT_REPARAMETERIZED,
        validate_args=validate_args,
        allow_nan_stats=allow_nan_stats,
        parameters=parameters,
        graph_parents=[self._rate],
        name=name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:35,代码来源:poisson.py

示例13: _check_diag

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _check_diag(self, diag):
    """Verify that `diag` is positive."""
    diag = ops.convert_to_tensor(diag, name="diag")
    if not self.verify_pd:
      return diag
    deps = [check_ops.assert_positive(diag)]
    return control_flow_ops.with_dependencies(deps, diag) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:operator_pd_diag.py

示例14: _maybe_validate_identity_multiplier

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_validate_identity_multiplier(self, identity_multiplier,
                                          validate_args):
    """Check that the init arg `identity_multiplier` is valid."""
    if identity_multiplier is None or not validate_args:
      return identity_multiplier
    if validate_args:
      identity_multiplier = control_flow_ops.with_dependencies(
          [check_ops.assert_positive(identity_multiplier)],
          identity_multiplier)
    return identity_multiplier 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:affine_impl.py

示例15: _maybe_assert_valid_y

# 需要导入模块: from tensorflow.python.ops import check_ops [as 别名]
# 或者: from tensorflow.python.ops.check_ops import assert_positive [as 别名]
def _maybe_assert_valid_y(self, y):
    if not self.validate_args:
      return y
    is_valid = check_ops.assert_positive(
        y, message="Inverse transformation input must be greater than 0.")
    return control_flow_ops.with_dependencies([is_valid], y) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:power_transform_impl.py


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