text_plain_output_1.png
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout

from keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D

from keras.models import Model

from keras.preprocessing.image import ImageDataGenerator

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

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

x_train = train_data.drop(labels='label', axis=1)

x_train = x_train / 255
test_data = test_data / 255

X_train = x_train.values.reshape(x_train.shape[0], 28, 28, 1)
X_test = test_data.values.reshape(test_data.shape[0], 28, 28, 1)

def keras_model(input_shape):
    X_input = Input(input_shape)
    X = ZeroPadding2D((3, 3))(X_input)
    X = Conv2D(48, (5, 5), strides=(1, 1), name='conv0')(X)
    X = BatchNormalization(axis=3, name='bn0')(X)
    X = Activation('relu')(X)
    X = Conv2D(32, (3, 3), strides=(1, 1), name='conv1')(X)
    X = BatchNormalization(axis=3, name='bn1')(X)
    X = Activation('relu')(X)
    X = Conv2D(16, (3, 3), strides=(1, 1), name='conv2')(X)
    X = BatchNormalization(axis=3, name='bn2')(X)
    X = Activation('relu')(X)
    X = MaxPooling2D((2, 2), name='max_pool')(X)
    X = Flatten()(X)
    X = Dense(10, activation='sigmoid', name='fc1')(X)
    model = Model(inputs=X_input, output=X, name='digit_model')
    return model

model = keras_model(X_train_split[0].shape)

model.compile(optimizer='Adam', loss='categorical_crossentropy', 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)
batch_size = 16
epochs = 15
history = model.fit_generator(datagen.flow(X_train_split, y_train_split, batch_size=batch_size), epochs=epochs, validation_data=(X_test_split, y_test_split), verbose=2, steps_per_epoch=X_train_split.shape[0] // batch_size)