[null,null,["Last updated 2023-03-17 UTC."],[],[],null,["# tf.data.experimental.assert_cardinality\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.9.3/tensorflow/python/data/experimental/ops/cardinality.py#L67-L96) |\n\nAsserts the cardinality of the input dataset.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.data.experimental.assert_cardinality`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/assert_cardinality)\n\n\u003cbr /\u003e\n\n tf.data.experimental.assert_cardinality(\n expected_cardinality\n )\n\n**Note:** The following assumes that \"examples.tfrecord\" contains 42 records. \n\n dataset = tf.data.TFRecordDataset(\"examples.tfrecord\")\n cardinality = tf.data.experimental.cardinality(dataset)\n print((cardinality == tf.data.experimental.UNKNOWN_CARDINALITY).numpy())\n True\n dataset = dataset.apply(tf.data.experimental.assert_cardinality(42))\n print(tf.data.experimental.cardinality(dataset).numpy())\n 42\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|------------------------------------------------|\n| `expected_cardinality` | The expected cardinality of the input dataset. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Dataset` transformation function, which can be passed to [`tf.data.Dataset.apply`](../../../tf/data/Dataset#apply). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| `FailedPreconditionError` | The assertion is checked at runtime (when iterating the dataset) and an error is raised if the actual and expected cardinality differ. |\n\n\u003cbr /\u003e"]]