class_docstr: Adapter that handles `tf.data.Dataset`.
class_docstr_tok: ["Adapter","that","handles","`","tf.data.Dataset","`","."]
code: 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 Infiite cardinality datasets
      if cardinality < 0:
          return None
      return cardinality
  
file_path: keras/keras/trainers/data_adapters/tf_dataset_adapter.py
imports: import numpy
  import tree
  from keras.trainers.data_adapters import data_adapter_utils
  from keras.trainers.data_adapters.data_adapter import DataAdapter
label_desc: Use image node_id 4 for calling the TFDatasetAdapter obj's underlying member method code with example usage: obj.num_batches() and returns: cardinality, None