I create a TensorFlow dataset with elements from 0 to 49, then filter it by only keep elements less than 25, as follows
import tensorflow as tf
dataset = tf.data.Dataset.range(50)
dataset_less_25 = dataset.filter(lambda x: x < 25)
However, when I check the cardinality of the new dataset as follows:
dataset_less_25.cardinality().numpy()
It returns -2, which does not make sense. I further checked that the new dataset actually contains 25 elements, so I wonder why cardinality() function does not work in this case?