Search code examples
tensorflowkeras

how to obtain the number of files in tf.keras.preprocessing.image_dataset_from_directory


how to obtain the number of files in tf.keras.preprocessing.image_dataset_from_directory?

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    data_dir,
    validation_split=0.2,
    subset="training",
    seed=123,
    image_size=(img_height, img_width),
    batch_size=batch_size)

Found 3670 files belonging to 5 classes. Using 2936 files for training.


Solution

  • When you run

    import numpy as np
    
    len(np.concatenate([i for x, i in train_ds], axis=0))
    

    this gives you the number of files, in this case 2936.