Clarify assert docs
PiperOrigin-RevId: 303125125 Change-Id: Ib69a093f0e9723cd275f1d6e55dddb1c44ca5765
This commit is contained in:
parent
f7132de3d4
commit
f8c45a5b38
@ -117,16 +117,6 @@ def Assert(condition, data, summarize=None, name=None):
|
|||||||
If `condition` evaluates to false, print the list of tensors in `data`.
|
If `condition` evaluates to false, print the list of tensors in `data`.
|
||||||
`summarize` determines how many entries of the tensors to print.
|
`summarize` determines how many entries of the tensors to print.
|
||||||
|
|
||||||
NOTE: In graph mode, to ensure that Assert executes, one usually attaches
|
|
||||||
a dependency:
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Ensure maximum element of x is smaller or equal to 1
|
|
||||||
assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x])
|
|
||||||
with tf.control_dependencies([assert_op]):
|
|
||||||
... code using x ...
|
|
||||||
```
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
condition: The condition to evaluate.
|
condition: The condition to evaluate.
|
||||||
data: The tensors to print out when condition is false.
|
data: The tensors to print out when condition is false.
|
||||||
@ -141,8 +131,17 @@ def Assert(condition, data, summarize=None, name=None):
|
|||||||
@end_compatibility
|
@end_compatibility
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
@compatibility(eager)
|
@compatibility(TF1)
|
||||||
`tf.errors.InvalidArgumentError` if `condition` is not true
|
When in TF V1 mode (that is, outside `tf.function`) Assert needs a control
|
||||||
|
dependency on the output to ensure the assertion executes:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Ensure maximum element of x is smaller or equal to 1
|
||||||
|
assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x])
|
||||||
|
with tf.control_dependencies([assert_op]):
|
||||||
|
... code using x ...
|
||||||
|
```
|
||||||
|
|
||||||
@end_compatibility
|
@end_compatibility
|
||||||
"""
|
"""
|
||||||
if context.executing_eagerly():
|
if context.executing_eagerly():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user