How can I get the size or the len of the dataset after applying a filter. Using tf.data.experimental.cardinality give -2, and this is not what I am looking for!! I want to know how many filtered samples exist in my dataset in order to be able to split it to training and validation datasets using take() and skip().
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5]) dataset = dataset.filter(lambda x: x < 4) size = tf.data.experimental.cardinality(dataset).numpy() #size here is equal to -2 but I want to get the real size which is 3
My dataset contains images and their labels, this is just an illustrative example