description: Asserts the cardinality of the input dataset.
tf.data.experimental.assert_cardinality
Asserts the cardinality of the input dataset.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.data.experimental.assert_cardinality
tf.data.experimental.assert_cardinality(
expected_cardinality
)
NOTE: The following assumes that "examples.tfrecord" contains 42 records.
>>> dataset = tf.data.TFRecordDataset("examples.tfrecord")
>>> cardinality = tf.data.experimental.cardinality(dataset)
>>> print((cardinality == tf.data.experimental.UNKNOWN_CARDINALITY).numpy())
True
>>> dataset = dataset.apply(tf.data.experimental.assert_cardinality(42))
>>> print(tf.data.experimental.cardinality(dataset).numpy())
42
Args |
expected_cardinality
|
The expected cardinality of the input dataset.
|
Raises |
FailedPreconditionError
|
The assertion is checked at runtime (when iterating
the dataset) and an error is raised if the actual and expected cardinality
differ.
|