Python tensorflow.python.ops.check_ops.assert_positive() Examples
The following are 30
code examples of tensorflow.python.ops.check_ops.assert_positive().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.ops.check_ops
, or try the search function
.
Example #1
Source File: operator_pd_cholesky.py From lambda-packs with MIT License | 6 votes |
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)
Example #2
Source File: operator_pd_cholesky.py From auto-alt-text-lambda-api with MIT License | 6 votes |
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)
Example #3
Source File: operator_pd_cholesky.py From deep_image_model with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: tf_image.py From MobileNet with Apache License 2.0 | 5 votes |
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 []
Example #5
Source File: image_ops.py From deep_image_model with Apache License 2.0 | 5 votes |
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 []
Example #6
Source File: attention_wrapper.py From tf-var-attention with MIT License | 5 votes |
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)
Example #7
Source File: attention_wrapper.py From OpenSeq2Seq with Apache License 2.0 | 5 votes |
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)
Example #8
Source File: attention_wrapper.py From QGforQA with MIT License | 5 votes |
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)
Example #9
Source File: attention_wrapper_mod.py From NQG_ASs2s with MIT License | 5 votes |
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)
Example #10
Source File: tf_image.py From pixel_link with MIT License | 5 votes |
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 []
Example #11
Source File: gamma.py From deep_image_model with Apache License 2.0 | 5 votes |
def _log_cdf(self, x): x = control_flow_ops.with_dependencies([check_ops.assert_positive(x)] if self.validate_args else [], x) contrib_tensor_util.assert_same_float_dtype(tensors=[x], dtype=self.dtype) # Note that igamma returns the regularized incomplete gamma function, # which is what we want for the CDF. return math_ops.log(math_ops.igamma(self.alpha, self.beta * x))
Example #12
Source File: hyperspherical_uniform.py From s-vae-tf with MIT License | 5 votes |
def __init__(self, dim, dtype=dtypes.float32, validate_args=False, allow_nan_stats=True, name="HypersphericalUniform"): """Initialize a batch of Hyperspherical Uniform distributions. Args: dim: Integer tensor, dimensionality of the distribution(s). Must be `dim > 0`. 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. Raises: InvalidArgumentError: if `dim > 0` and `validate_args=False`. """ parameters = locals() with ops.name_scope(name, values=[dim]): with ops.control_dependencies([check_ops.assert_positive(dim), check_ops.assert_integer(dim), check_ops.assert_scalar(dim)] if validate_args else []): self._dim = dim super(HypersphericalUniform, self).__init__( dtype=dtype, reparameterization_type=distribution.FULLY_REPARAMETERIZED, validate_args=validate_args, allow_nan_stats=allow_nan_stats, parameters=parameters, graph_parents=[], name=name)
Example #13
Source File: von_mises_fisher.py From s-vae-tf with MIT License | 5 votes |
def __init__(self, loc, scale, validate_args=False, allow_nan_stats=True, name="von-Mises-Fisher"): """Construct von-Mises-Fisher distributions with mean and concentration `loc` and `scale`. Args: loc: Floating point tensor; the mean of the distribution(s). scale: Floating point tensor; the concentration of the distribution(s). Must contain only non-negative values. 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. Raises: TypeError: if `loc` and `scale` have different `dtype`. """ parameters = locals() with ops.name_scope(name, values=[loc, scale]): with ops.control_dependencies([check_ops.assert_positive(scale), check_ops.assert_near(linalg_ops.norm(loc, axis=-1), 1, atol=1e-7)] if validate_args else []): self._loc = array_ops.identity(loc, name="loc") self._scale = array_ops.identity(scale, name="scale") check_ops.assert_same_float_dtype([self._loc, self._scale]) super(VonMisesFisher, self).__init__( dtype=self._scale.dtype, reparameterization_type=distribution.FULLY_REPARAMETERIZED, validate_args=validate_args, allow_nan_stats=allow_nan_stats, parameters=parameters, graph_parents=[self._loc, self._scale], name=name) self.__m = math_ops.cast(self._loc.shape[-1], dtypes.int32) self.__mf = math_ops.cast(self.__m, dtype=self.dtype) self.__e1 = array_ops.one_hot([0], self.__m, dtype=self.dtype)
Example #14
Source File: inverse_gamma.py From deep_image_model with Apache License 2.0 | 5 votes |
def _log_prob(self, x): x = control_flow_ops.with_dependencies([check_ops.assert_positive(x)] if self.validate_args else [], x) return (self.alpha * math_ops.log(self.beta) - math_ops.lgamma(self.alpha) - (self.alpha + 1.) * math_ops.log(x) - self.beta / x)
Example #15
Source File: inverse_gamma.py From deep_image_model with Apache License 2.0 | 5 votes |
def _cdf(self, x): x = control_flow_ops.with_dependencies([check_ops.assert_positive(x)] if self.validate_args else [], x) # Note that igammac returns the upper regularized incomplete gamma # function Q(a, x), which is what we want for the CDF. return math_ops.igammac(self.alpha, self.beta / x)
Example #16
Source File: dirichlet_multinomial.py From deep_image_model with Apache License 2.0 | 5 votes |
def _assert_valid_alpha(self, alpha, validate_args): alpha = ops.convert_to_tensor(alpha, name="alpha") if not validate_args: return alpha return control_flow_ops.with_dependencies( [check_ops.assert_rank_at_least(alpha, 1), check_ops.assert_positive(alpha)], alpha)
Example #17
Source File: gamma.py From deep_image_model with Apache License 2.0 | 5 votes |
def _log_prob(self, x): x = control_flow_ops.with_dependencies([check_ops.assert_positive(x)] if self.validate_args else [], x) contrib_tensor_util.assert_same_float_dtype(tensors=[x], dtype=self.dtype) return (self.alpha * math_ops.log(self.beta) + (self.alpha - 1.) * math_ops.log(x) - self.beta * x - math_ops.lgamma(self.alpha))
Example #18
Source File: datasets.py From self-supervision with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 []
Example #19
Source File: linear_operator_tril.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _assert_positive_definite(self): if self.dtype.is_complex: message = ( "Diagonal operator had diagonal entries with non-positive real part, " "thus was not positive definite.") else: message = ( "Real diagonal operator had non-positive diagonal entries, " "thus was not positive definite.") return check_ops.assert_positive( math_ops.real(self._diag), message=message)
Example #20
Source File: linear_operator_identity.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _assert_positive_definite(self): return check_ops.assert_positive( math_ops.real(self.multiplier), message="LinearOperator was not positive definite.")
Example #21
Source File: linear_operator_identity.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _assert_non_singular(self): return check_ops.assert_positive( math_ops.abs(self.multiplier), message="LinearOperator was singular")
Example #22
Source File: linear_operator_diag.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _assert_positive_definite(self): if self.dtype.is_complex: message = ( "Diagonal operator had diagonal entries with non-positive real part, " "thus was not positive definite.") else: message = ( "Real diagonal operator had non-positive diagonal entries, " "thus was not positive definite.") return check_ops.assert_positive( math_ops.real(self._diag), message=message)
Example #23
Source File: dirichlet.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _assert_valid_sample(self, x): if not self.validate_args: return x return control_flow_ops.with_dependencies([ check_ops.assert_positive(x), distribution_util.assert_close( array_ops.ones((), dtype=self.dtype), math_ops.reduce_sum(x, reduction_indices=[-1])), ], x)
Example #24
Source File: operator_pd_diag.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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)
Example #25
Source File: bijector.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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
Example #26
Source File: bijector.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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)
Example #27
Source File: poisson.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def __init__(self, lam, validate_args=False, allow_nan_stats=True, name="Poisson"): """Construct Poisson distributions. Args: lam: Floating point tensor, the rate parameter of the distribution(s). `lam` must be positive. validate_args: `Boolean`, default `False`. Whether to assert that `lam > 0` as well as inputs to pmf computations are non-negative integers. If validate_args is `False`, then `pmf` computations might return `NaN`, but can be evaluated at any real value. allow_nan_stats: `Boolean`, default `True`. If `False`, raise an exception if a statistic (e.g. mean/mode/etc...) is undefined for any batch member. If `True`, batch members with valid parameters leading to undefined statistics will return NaN for this statistic. name: A name for this distribution. """ parameters = locals() parameters.pop("self") with ops.name_scope(name, values=[lam]) as ns: with ops.control_dependencies([check_ops.assert_positive(lam)] if validate_args else []): self._lam = array_ops.identity(lam, name="lam") super(Poisson, self).__init__( dtype=self._lam.dtype, is_continuous=False, is_reparameterized=False, validate_args=validate_args, allow_nan_stats=allow_nan_stats, parameters=parameters, graph_parents=[self._lam], name=ns)
Example #28
Source File: beta.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _assert_valid_sample(self, x): """Check x for proper shape, values, then return tensor version.""" if not self.validate_args: return x return control_flow_ops.with_dependencies([ check_ops.assert_positive( x, message="Negative events lie outside Beta distribution support."), check_ops.assert_less( x, array_ops.ones((), self.dtype), message="Event>=1 lies outside Beta distribution support."), ], x)
Example #29
Source File: inverse_gamma.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _cdf(self, x): x = control_flow_ops.with_dependencies([check_ops.assert_positive(x)] if self.validate_args else [], x) # Note that igammac returns the upper regularized incomplete gamma # function Q(a, x), which is what we want for the CDF. return math_ops.igammac(self.alpha, self.beta / x)
Example #30
Source File: inverse_gamma.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _log_prob(self, x): x = control_flow_ops.with_dependencies([check_ops.assert_positive(x)] if self.validate_args else [], x) return (self.alpha * math_ops.log(self.beta) - math_ops.lgamma(self.alpha) - (self.alpha + 1.) * math_ops.log(x) - self.beta / x)