<jupyter_start><jupyter_text>Data Augmentation Image data augmentation is a technique that can be used to artificially expand the size of a training dataset by creating modified versions of images in the dataset.Training deep learning neural network models on more data can result in more skillful models, and the augmentation techniques can create variations of the images that can improve the ability of the fit models to generalize what they have learned to new images. - Image flips via the horizontal_flip and vertical_flip arguments.- Image rotations via the rotation_range argument- Image brightness via the brightness_range argument.- Image zoom via the zoom_range argument. [Source](https://machinelearningmastery.com/how-to-configure-image-data-augmentation-when-training-deep-learning-neural-networks/)<jupyter_code>from IPython.core.display import display, HTML
display(HTML("<style>.container { width:95% !important; }</style>"))
import os
import random
import numpy as np

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator

import matplotlib.pyplot as plt
%matplotlib inline
# this function will plot images in the form of a grid with 1 row and 10 columns.

def plotImages(images_array):
    
    fig, axes = plt.subplots(1, 10, figsize=(20, 20))
    axes = axes.flatten()
    
    for img, ax in zip(images_array, axes):
        ax.imshow(img)
        ax.axis('off')
        
    plt.tight_layout()
    plt.show()
# Check out 'ImageDataGenerator' documentation

gen = ImageDataGenerator( rotation_range=10, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.15, 
                          zoom_range=0.1, channel_shift_range=10, horizontal_flip=True )<jupyter_output><empty_output><jupyter_text>Choosing image to perform Data Augmentation on.....<jupyter_code>image_path = '/home/satyam/Desktop/GIT/helper-notebooks-data-science/MobileNet-architecture/data/MobileNet-samples/1.jpeg'
image = np.expand_dims(plt.imread(image_path), 0)
plt.imshow(image[0])<jupyter_output><empty_output><jupyter_text>Generate batches of augmented images from the above image<jupyter_code>aug_iter = gen.flow(image)<jupyter_output><empty_output><jupyter_text>>>> Get  '10'  samples of augmented images<jupyter_code>aug_images = [next(aug_iter)[0].astype(np.uint8) for i in range(10)]<jupyter_output><empty_output><jupyter_text>>>> Following are 10 samples of augmented images<jupyter_code>plotImages(aug_images)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0890302066772655, 'fraction_numerical': 0.014308426073131956, 'mean_word_length': 5.437340153452685, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '363912', 'license': 'MIT', 'n_tokens_mistral': 790, 'n_tokens_neox': 738, 'n_words': 222, 'path': 'Data-Augmentation-helper-Notebook/DataAugmentation-helper.ipynb', 'repo_name': 'satyam9753/helper-notebooks-data-science', 'size': '2516'}