PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

[FIXED] How tf.keras.preprocessing.image_dataset_from_directory display output to console

 August 16, 2022     keras, output, python, tensorflow     No comments   

Issue

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?


Solution

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.



Answered By - Lescurel
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing