Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Introduction

Setup

ANN

Working process ANN

Propagation

Bias parameter

Activation function

Loss function

Overfitting and Underfitting

Optimization function

Chain rule

Minima

Gradient problem

Weight initialization

Dropout

ANN Regression Exercise

ANN Classification Exercise

Hyper parameter tuning

CNN

CNN basics

Convolution

Padding

Pooling

Data argumentation

Flattening

Create Custom Dataset

Binary Classification Exercise

Multiclass Classification Exercise

Transfer learning

Transfer model Basic template

RNN

How RNN works

LSTM

Bidirectional RNN

Sequence to sequence

Attention model

Transformer model

Bag of words

Tokenization & Stop words

Stemming & Lemmatization

TF-IDF

N-Gram

Word embedding

Normalization

Pos tagging

Parser

semantic analysis

Regular expression

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Learn about data argumentation in cnn

What is data argumentation?

Suppose we give cat and dog images to our CNN model and then it predicts that is it a cat or dog. So our model learns from a normal cat image but when we give a new cat image then that image can be flipped, rotated, horizontally shifted, vertically shifted, etc. So in data preprocessing, we create different images from one image.
Suppose we will take a cat image and will create a flipped image, rotated image, zoom image, etc images so that when our CNN model gets a flipped image of a cat it can recognize that cat image.

Let's see code using keras

Input
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

'''
Here we write all the code to generate various images of data argumentation like rotation, zoom, shift, etc.
'''
datagen = ImageDataGenerator(
     width_shift_range=0.3,
     rotation_range=50,
     height_shift_range=0.3,
     shear_range=0.3,
     zoom_range=0.3,
     horizontal_flip=True,
     fill_mode='nearest')

#here we will load the image.
img = load_img("D:\\Final practice sheet and document and code\\final practice machine learning datasets\\cat1.jpg") '''
This is a PIL image. Here we will convert our image into array.
This is a Numpy array with shape (3, 150, 150)
'''
x = img_to_array(img)

'''
Here we will reshape our image.
this is a Numpy array with image shape (1, 3, 150, 150)
'''
x = x.reshape((1,) + x.shape)

'''
the .flow() command below generates batches of randomly transformed images
and saves the results to the `preview/` directory
'''

i = 0
for batch in datagen.flow(x, batch_size=1, save_to_dir='C:\\Users\\HP\\OneDrive\\Desktop\\preview', save_prefix='cat', save_format='jpeg'):
   i += 1
   '''
Here 30 means we want to save 30 images. We can change the number according to our need.
'''
   if i > 30:
      break
Output

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.