- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can Tensorflow be used with pre-trained model to build the training and validation dataset?
Tensorflow can be used with pre-trained model to build the training and validation dataset with the help of the ‘image_dataset_from_directory’ method. This method takes the batch size, image size, and whether to shuffle or not values as parameters, along with the training data or validation data respectively.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
We will understand how to classify images of cats and dogs with the help of transfer learning from a pre-trained network.
The intuition behind transfer learning for image classification is, if a model is trained on a large and general dataset, this model can be used to effectively serve as a generic model for the visual world. It would have learned the feature maps, which means the user won’t have to start from scratch by training a large model on a large dataset.
Read More: How can a customized model be pre-trained?
We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.
Example
print("Training dataset") train_dataset = image_dataset_from_directory(train_dir, shuffle=True, batch_size=BATCH_SIZE, image_size=IMG_SIZE) print("Validation dataset") validation_dataset = image_dataset_from_directory(validation_dir, shuffle=True, batch_size=BATCH_SIZE, image_size=IMG_SIZE)
Code credit −https://www.tensorflow.org/tutorials/images/transfer_learning
Output
Training dataset Found 2000 files belonging to 2 classes. Validation dataset Found 1000 files belonging to 2 classes.
Explanation
The training and validation dataset are built using the downloaded images of cats and dogs.
- Related Articles
- How can Tensorflow and pre-trained model be used to continue training the model using Python?
- How can Tensorflow and pre-trained model be used to configure the dataset for performance?
- How can Tensorflow and pre-trained model be used to create base model from pre-trained convnets?
- How can Tensorflow be used with pre-trained model to determine the number of batches in the dataset?
- How can Tensorflow and pre-trained model be used to see the changes during training after every epoch?
- How can Tensorflow be used to pre-process the flower training dataset?
- How can Tensorflow used with the pre-trained model to compile the model?
- How can Tensorflow be used with pre-trained model to rescale pixel values?
- How can Tensorflow and pre-trained model be used to compile the model using Python?
- How can Tensorflow be used with flower dataset to continue training the model?
- How can Tensorflow and pre-trained model be used for feature extraction?
- How can Tensorflow and pre-trained model be used for fine tuning?
- How can Tensorflow be used to split the flower dataset into training and validation?
- How can Tensorflow and pre-trained model be used to add classification head to the model?
- How can Tensorflow and pre-trained model be used to understand the learning curve?
