It is the same explained with cardinality you don’t have the len available with from_generator.

  

      github.com
  

  
    tensorflow/tensorflow/blob/master/tensorflow/python/data/ops/dataset_ops.py#L419-L425 12



      
      
          def __len__(self):
            """Returns the length of the dataset if it is known and finite.
          
          
  This method requires that you are running in eager mode, and that the
            length of the dataset is known and non-infinite. When the length may be
            unknown or infinite, or if you are running in graph mode, use
            `tf.data.Dataset.cardinality` instead.