Skip to content

Instantly share code, notes, and snippets.

View saimadhu-polamuri's full-sized avatar
💭
For the love of data.

saimadhu saimadhu-polamuri

💭
For the love of data.
View GitHub Profile
## Regularization applyied model train and test error
plt.plot(history.history['loss'], label='train')
plt.plot(history.history['val_loss'], label='test')
plt.legend()
plt.show()
## Model with Dropout
from tensorflow.keras.layers import Dropout
model = Sequential()
model.add(Dense(500, input_dim=2, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
## Dropout applyied model train and test error
plt.plot(history.history['loss'], label='train')
plt.plot(history.history['val_loss'], label='test')
plt.legend()
plt.show()
## Data augmentation code
from keras.preprocessing.image import ImageDataGenerator
aug = ImageDataGenerator(
rotation_range=20,
zoom_range=0.15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.15,
## EarlyStopping with keras
from tensorflow.keras.callbacks import EarlyStopping
model = Sequential()
model.add(Dense(128, input_dim=2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
## EarlyStopping applyied model train and test error
plt.plot(history.history['loss'], label='train')
plt.plot(history.history['val_loss'], label='test')
plt.legend()
plt.show()
"""
===============================================
Objective: 4 different techniques to handle overfitting in deep learning models
Author: Jaiganesh Nagidi
Blog: https://dataaspirant.com
Date: 2020-08-23
===============================================
"""
# Reading the image
import matplotlib.image as mpimg
image = mpimg.imread('catimage.jpg')
# Reshape Image
import numpy as np
image = np.expand_dims(image, axis=0)
# ImageDataGenerator Instance creation
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator()