@@ -0,0 +1,2518 @@
+from __future__ import print_function%0D%0A%0D%0Afrom keras.datasets import mnist%0D%0Afrom keras.models import Sequential%0D%0Afrom keras.layers.core import Dense, Dropout, Activation, Flatten%0D%0Afrom keras.layers.convolutional import Convolution2D, MaxPooling2D%0D%0Afrom keras.utils import np_utils%0D%0A%0D%0Afrom myutils import draw_accuracy, draw_loss%0D%0A%0D%0Abatch_size = 128%0D%0Anb_classes = 10%0D%0Anb_epoch = 12%0D%0A%0D%0A# input image dimensions%0D%0Aimg_rows, img_cols = 28, 28%0D%0A%0D%0A# number of convolutional filters to use%0D%0Anb_filters = 32%0D%0A%0D%0A# size of pooling area for max pooling%0D%0Anb_pool = 2%0D%0A%0D%0A# convolution kernel size%0D%0Anb_conv = 3%0D%0A%0D%0Aif __name__ == '__main__':%0D%0A    # load MNIST data%0D%0A    (X_train, y_train), (X_test, y_test) = mnist.load_data()%0D%0A%0D%0A    X_train = X_train.reshape(X_train.shape%5B0%5D, 1, img_rows, img_cols).astype('float32')%0D%0A    X_test = X_test.reshape(X_test.shape%5B0%5D, 1, img_rows, img_cols).astype('float32')%0D%0A    X_train /= 255.0%0D%0A    X_test /= 255.0%0D%0A%0D%0A    # convert class vectors to 1-of-K format%0D%0A    y_train = np_utils.to_categorical(y_train, nb_classes)%0D%0A    y_test = np_utils.to_categorical(y_test, nb_classes)%0D%0A%0D%0A    print('train samples: ', X_train.shape)%0D%0A    print('test samples: ', X_test.shape)%0D%0A%0D%0A    # building the model%0D%0A    print('building the model ...')%0D%0A%0D%0A    model = Sequential()%0D%0A%0D%0A    model.add(Convolution2D(nb_filters, nb_conv, nb_conv,%0D%0A                            border_mode='valid',%0D%0A                            input_shape=(1, img_rows, img_cols)))%0D%0A    model.add(Activation('relu'))%0D%0A%0D%0A    model.add(Convolution2D(nb_filters, nb_conv, nb_conv))%0D%0A    model.add(Activation('relu'))%0D%0A%0D%0A    model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))%0D%0A    model.add(Dropout(0.25))%0D%0A%0D%0A    model.add(Flatten())%0D%0A    model.add(Dense(128))%0D%0A    model.add(Activation('relu'))%0D%0A    model.add(Dropout(0.5))%0D%0A%0D%0A    model.add(Dense(nb_classes))%0D%0A    model.add(Activation('softmax'))%0D%0A%0D%0A    model.compile(loss='categorical_crossentropy', optimizer='adadelta')%0D%0A%0D%0A    # training%0D%0A    hist = model.fit(X_train, y_train,%0D%0A                     batch_size=batch_size,%0D%0A                     nb_epoch=nb_epoch,%0D%0A                     show_accuracy=True,%0D%0A                     verbose=1,%0D%0A                     validation_split=0.1)%0D%0A%0D%0A    # evaluation%0D%0A    score = model.evaluate(X_test, y_test,%0D%0A                           show_accuracy=True, verbose=1)%0D%0A    print('Test score:', score%5B0%5D)%0D%0A    print('Test accuracy:', score%5B1%5D)%0D%0A%0D%0A    # draw accuracy/loss plot%0D%0A    draw_accuracy(hist, title='cnn')%0D%0A    draw_loss(hist, title='cnn')%0D%0A

Add mnist_cnn.py