Skip to content

Instantly share code, notes, and snippets.

View PallawiSinghal's full-sized avatar
🎯
Focusing

Pallawi Rajendra PallawiSinghal

🎯
Focusing
View GitHub Profile
@PallawiSinghal
PallawiSinghal / data_augmentation.py
Last active March 7, 2019 12:09
This code helps to understand how data augmentation works in Keras.
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras import backend as K
no_train_img,no_validation_img = 1001,800
img_width, img_height = 150, 150
batch_size = 16
if K.image_data_format() == 'channels_first':
input_shape = (3, img_width, img_height)#theano
#import all dependencies
import PIL
import keras
import numpy as np
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
print ("\n")
print("Your backend is ----------------------------------------------------------------->",keras.backend.backend())
#import all dependencies
import PIL
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
import numpy as np
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
import cv2
import numpy as np
filename = '/dog_clip.png'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)
# Import necessary components to build LeNet
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Conv2D, MaxPooling2D, ZeroPadding2D
from keras.layers.normalization import BatchNormalization
from keras.regularizers import l2
# Initialize model
alexnet = Sequential()
# set the matplotlib backend so figures can be saved in the background
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from sklearn.preprocessing import LabelBinarizer
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from keras.models import Sequential
# set the matplotlib backend so figures can be saved in the background
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from sklearn.preprocessing import LabelBinarizer
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from keras.models import Sequential
# import the necessary packages
from keras.models import load_model
import argparse
import pickle
import cv2
import os
test_image_path = "/test_image/cats.jpg"
# import the necessary packages
from keras.models import load_model
import argparse
import pickle
import cv2
import os
import imutils
test_image_path = "/panda_00125.jpg"
model_path = "/simple_binary_classifcation_model.model"