from __future__ import absolute_import from __future__ import print_function import pylab as pl import matplotlib.cm as cm import numpy as np np . random . seed ( 1337 ) # for reproducibility from keras.datasets import mnist from keras.models import Sequential from keras.layers.core import Dense , Dropout , Activation , Flatten from keras.layers.convolutional import Convolution2D , MaxPooling2D from keras.utils import np_utils ''' Train a simple convnet on the MNIST dataset. Run on GPU: THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python mnist_cnn.py Get to 99.25% test accuracy after 12 epochs (there is still a lot of margin for parameter tuning). 16 seconds per epoch on a GRID K520 GPU. '''