<jupyter_start><jupyter_text>Dosa / No Dosa - Image Augmentation  Frame the Problem We want to classify the images in two categories - **Dosa** and **No-Dosa**. This is a classical two-class image classification problem.- Dosa- No-Dosa  Acquire the DataThese images very downloaded google.com/images with "reuse with modification" filter to allow for commercial reuse.<jupyter_code>#!mkdir data
#!wget https://bit.do/dosa-nodosa -O data/food-binary.zip
#!cd data && unzip food-binary.zip<jupyter_output><empty_output><jupyter_text>Load basic libraries<jupyter_code>import numpy as np
import pandas as pd
import keras
import matplotlib.pyplot as plt
%matplotlib inline
import vis<jupyter_output>Using TensorFlow backend.<jupyter_text>Image Augementation<jupyter_code>from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
img = load_img('data/food-binary/Dosa/img39.jpeg')
# Read as matrix and see shape
image = img_to_array(img)
image.shape
datagen = ImageDataGenerator(rotation_range=45,
                             rescale=1/255,
                             width_shift_range=0.2, 
                             height_shift_range=0.2)
import importlib
importlib.reload(vis)
vis.show_single_image_gen(datagen, image, 10)<jupyter_output><empty_output><jupyter_text>CNN with Image Augementation **Step 1: Prepare the images and labels**<jupyter_code>data = ImageDataGenerator(validation_split=0.2, 
                          rescale=1/255,
                          samplewise_center=True, # set input mean to 0 over the sample
                          samplewise_std_normalization=True,  # divide inputs by std of the sample
                          rotation_range=90,       # randomly rotate images in the range (degrees, 0 to 180)
                          width_shift_range=0.2,   # randomly shift images horizontally (fraction of total width)
                          height_shift_range=0.2,  # randomly shift images vertically (fraction of total height)
                          fill_mode='reflect',     # filling the area outside
                          zoom_range=0.4,          # random zoom
                          horizontal_flip=True,    # randomly flip images
                          vertical_flip=True)      # randomly flip images
train_generator = data.flow_from_directory(directory="data/food-binary/", 
                                           target_size=(224,224),
                                           class_mode="categorical", 
                                           shuffle=True, 
                                           batch_size=8, 
                                           subset='training')
val_generator = data.flow_from_directory(directory="data/food-binary/", 
                                           target_size=(224,224),
                                           class_mode="categorical", 
                                           shuffle=True, 
                                           batch_size=8, 
                                           subset='validation')<jupyter_output>Found 65 images belonging to 2 classes.<jupyter_text>**Step 2: Craft the feature transfomation and classifier model **<jupyter_code>from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, Dense, Flatten
cnn = Sequential()
cnn.add(Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)))
cnn.add(MaxPooling2D(pool_size=(3, 3)))
cnn.add(Conv2D(32, (3, 3), activation='relu'))
cnn.add(MaxPooling2D(pool_size=(3, 3)))
cnn.add(Conv2D(64, (3, 3), activation='relu'))
cnn.add(MaxPooling2D(pool_size=(3, 3)))
cnn.add(Flatten())  # this converts our 3D feature maps to 1D feature vectors
cnn.add(Dense(64, activation='relu'))
cnn.add(Dropout(0.5))
cnn.add(Dense(2, activation='sigmoid'))
cnn.summary()
cnn.compile(loss='binary_crossentropy', optimizer="sgd", metrics=['accuracy'])
cnn_output =  cnn.fit_generator(train_generator, epochs=10, validation_data=val_generator, verbose = 2)
cnn_metrics = cnn_output.history
vis.metrics(cnn_metrics)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09333659970602645, 'fraction_numerical': 0.023272905438510533, 'mean_word_length': 2.433978132884777, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '638925', 'license': 'MIT', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1130, 'n_words': 271, 'path': '008-Data-Aug-DosaNoDosa.ipynb', 'repo_name': 'SaketJNU/deep-learning', 'size': '4082'}