cnn.py and mnist_demo.py are modified versions of scripts written by Sébastien Lugan