tf.debugging.assert_shapes
Stay organized with collections
Save and categorize content based on your preferences.
Assert tensor shapes and dimension size relationships between tensors.
tf.debugging.assert_shapes(
shapes, data=None, summarize=None, message=None, name=None
)
This Op checks that a collection of tensors shape relationships
satisfies given constraints.
Example:
n = 10
q = 3
d = 7
x = tf.zeros([n,q])
y = tf.ones([n,d])
param = tf.Variable([1.0, 2.0, 3.0])
scalar = 1.0
tf.debugging.assert_shapes([
(x, ('N', 'Q')),
(y, ('N', 'D')),
(param, ('Q',)),
(scalar, ()),
])
tf.debugging.assert_shapes([
(x, ('N', 'D')),
(y, ('N', 'D'))
])
Traceback (most recent call last):
ValueError: ...
If x
, y
, param
or scalar
does not have a shape that satisfies
all specified constraints, message
, as well as the first summarize
entries
of the first encountered violating tensor are printed, and
InvalidArgumentError
is raised.
Size entries in the specified shapes are checked against other entries by
their hash, except:
- a size entry is interpreted as an explicit size if it can be parsed as an
integer primitive.
- a size entry is interpreted as any size if it is None or '.'.
If the first entry of a shape is ...
(type Ellipsis
) or '*' that indicates
a variable number of outer dimensions of unspecified size, i.e. the constraint
applies to the inner-most dimensions only.
Scalar tensors and specified shapes of length zero (excluding the 'inner-most'
prefix) are both treated as having a single dimension of size one.
Args |
shapes
|
dictionary with (Tensor to shape) items, or a list of
(Tensor , shape) tuples. A shape must be an iterable.
|
data
|
The tensors to print out if the condition is False. Defaults to error
message and first few entries of the violating tensor.
|
summarize
|
Print this many entries of the tensor.
|
message
|
A string to prefix to the default message.
|
name
|
A name for this operation (optional). Defaults to "assert_shapes".
|
Raises |
ValueError
|
If static checks determine any shape constraint is violated.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.debugging.assert_shapes\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/check_ops.py#L1611-L1675) |\n\nAssert tensor shapes and dimension size relationships between tensors. \n\n tf.debugging.assert_shapes(\n shapes, data=None, summarize=None, message=None, name=None\n )\n\nThis Op checks that a collection of tensors shape relationships\nsatisfies given constraints.\n\n#### Example:\n\n n = 10\n q = 3\n d = 7\n x = tf.zeros([n,q])\n y = tf.ones([n,d])\n param = tf.Variable([1.0, 2.0, 3.0])\n scalar = 1.0\n tf.debugging.assert_shapes([\n (x, ('N', 'Q')),\n (y, ('N', 'D')),\n (param, ('Q',)),\n (scalar, ()),\n ])\n\n tf.debugging.assert_shapes([\n (x, ('N', 'D')),\n (y, ('N', 'D'))\n ])\n Traceback (most recent call last):\n\n ValueError: ...\n\nIf `x`, `y`, `param` or `scalar` does not have a shape that satisfies\nall specified constraints, `message`, as well as the first `summarize` entries\nof the first encountered violating tensor are printed, and\n`InvalidArgumentError` is raised.\n\nSize entries in the specified shapes are checked against other entries by\ntheir **hash**, except:\n\n- a size entry is interpreted as an explicit size if it can be parsed as an integer primitive.\n- a size entry is interpreted as *any* size if it is None or '.'.\n\nIf the first entry of a shape is `...` (type `Ellipsis`) or '\\*' that indicates\na variable number of outer dimensions of unspecified size, i.e. the constraint\napplies to the inner-most dimensions only.\n\nScalar tensors and specified shapes of length zero (excluding the 'inner-most'\nprefix) are both treated as having a single dimension of size one.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|------------------------------------------------------------------------------------------------------------------------------|\n| `shapes` | dictionary with (`Tensor` to shape) items, or a list of (`Tensor`, shape) tuples. A shape must be an iterable. |\n| `data` | The tensors to print out if the condition is False. Defaults to error message and first few entries of the violating tensor. |\n| `summarize` | Print this many entries of the tensor. |\n| `message` | A string to prefix to the default message. |\n| `name` | A name for this operation (optional). Defaults to \"assert_shapes\". |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------------|\n| `ValueError` | If static checks determine any shape constraint is violated. |\n\n\u003cbr /\u003e"]]