简体   繁体   中英

How tf.keras.preprocessing.image_dataset_from_directory display output to console

I am using the below function to read images from a directory

   train_ds = tf.keras.preprocessing.image_dataset_from_directory(directory=image_dataset_path,
                                                                   validation_split=0.2,
                                                                    subset='training',
                                                                    batch_size=32,
                                                                    color_mode='rgb',
                                                                    seed=1)

and it display below text in the output

Found 284 files belonging to 5 classes.
Using 228 files for training.

After exploring the above function here I am not able to find out how it is displaying the text in the console. One thing that I noticed is that the output of the function is a dataset but how does it generate the text in console?

Please help me understand How tf.keras is showing this output in the console. What is the exact code behind this?

Those two statements are the result of two helper functions used by tf.keras.preprocessing.image_dataset_from_directory .

See the relevant part of those functions below:

  • dataset_utils.index_directory .

     if labels is None: print('Found %d files.' % (len(filenames),)) else: print('Found %d files belonging to %d classes.' % (len(filenames), len(class_names)))
  • dataset_utils.get_training_or_validation_split

     if subset == 'training': print('Using %d files for training.' % (len(samples) - num_val_samples,)) samples = samples[:-num_val_samples] labels = labels[:-num_val_samples]

Those two helper functions simply print those messages in the standard output as a way to provide information to the developer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM