image_output_1.png
from keras.layers import Dense, Conv2DTranspose,Conv2D, MaxPooling2D

from keras.layers import Dropout, Flatten

from keras.models import Sequential

from keras.preprocessing.image import ImageDataGenerator

from keras.utils.np_utils import to_categorical

import pandas as pd

train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')

Y_train = train['label']
X_train = train.drop(labels=['label'], axis=1)

X_train = X_train / 255.0
test = test / 255.0

X_train = X_train.values.reshape(-1, 28, 28, 1)
test = test.values.reshape(-1, 28, 28, 1)

Y_train = to_categorical(Y_train, num_classes=10)

def baseline_model():
    model = Sequential()
    model.add(Conv2D(32, 3, input_shape=(28, 28, 1), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(64, 3, strides=1, padding='same', activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(128, 3, strides=1, padding='same', activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Conv2D(128, 3, strides=1, padding='same', activation='relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Flatten())
    model.add(Dense(512, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(10, activation='softmax'))
    return model

model = baseline_model()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

datagen = ImageDataGenerator(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=10, zoom_range=0.1, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=False, vertical_flip=False)
datagen.fit(X_train)

history = model.fit_generator(datagen.flow(X_train, Y_train, batch_size=50), epochs=3, validation_data=(X_val, Y_val), verbose=1, steps_per_epoch=X_train.shape[0] // 50)