Have a question? Connect with the community at the TensorFlow Forum Visit Forum


Asserts the cardinality of the input dataset.

Used in the notebooks

Used in the tutorials
dataset = tf.data.TFRecordDataset("examples.tfrecord")
cardinality = tf.data.experimental.cardinality(dataset)
print((cardinality == tf.data.experimental.UNKNOWN_CARDINALITY).numpy())
dataset = dataset.apply(tf.data.experimental.assert_cardinality(42))

expected_cardinality The expected cardinality of the input dataset.

A Dataset transformation function, which can be passed to tf.data.Dataset.apply.

FailedPreconditionError The assertion is checked at runtime (when iterating the dataset) and an error is raised if the actual and expected cardinality differ.