How can Tensorflow and re-trained model be used for data augmentation?


Tensorflow and the re-trained model can be used for data augmentation by using the ‘Sequential’ model that was created with two experimental layers namely ‘RandomFlip’ and ‘RandomRotation’.

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("Using data augmentation")
data_augmentation = tf.keras.Sequential([
   tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'),
   tf.keras.layers.experimental.preprocessing.RandomRotation(0.2),
])

Code credit −https://www.tensorflow.org/tutorials/images/transfer_learning

Output

Using data augmentation

Explanation

  • Sample diversity can be introduced when the user doesn’t have a large dataset.

  • This needs to be relaisitic, since it helps in transformations on the training images, such as rotation and horizontal flipping.

  • This helps expose model to different aspects of training data.

  • It also helps reduce overfitting.

Updated on: 25-Feb-2021

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements