keras/src/trainers/data_adapters/tf_dataset_adapter.py/TFDatasetAdapter/num_batches
class TFDatasetAdapter:    def num_batches(self):
        cardinality = self._dataset.cardinality
        if callable(cardinality):
            # `dataset.cardinality` is normally expected to be a callable.
            cardinality = int(self._dataset.cardinality())
        else:
            # However, in the case of `DistributedDataset`, it's a np.int64.
            cardinality = int(cardinality)
        # Return None for Unknown and Infinite cardinality datasets
        if cardinality < 0:
            return None
        return cardinality