Toy Models in Matlab and Python for different kind of Neural Networks
- CNN: 3 layer network, MNIST data
- RNN: 8 layer network, 8 bit binary digits
This is a simple 3 layer Convolutional Neural Network trained on MNIST data. Forward and backward pass are all programmed into one CNNtoymodel.m file (no libraries are needed). By intent there is only limited modularisation of functions. So it should be easy for you to see what is going on in the training loop and test loop by a glance at the MATLAB workspace. However, if you wish to check for the correctness of the model, you can also run an identical Tensorflow implementation by excecuting the CNNtoymodel.py in Python.
For more background info and practical excercises check out my CNN Technical Report (in German).
- Matlab: Just download the CNN folder and run
CNNtoymodel.min Matlab. - Python: Alternatively run the
CNNtoymodel.pyin Python.
For python you need to install the following dependencies:
numpy, tensorflow (I use version 12), random, matplotlib and scipy
One epoch, learning rate=0.01, batch size training=50, batch size test=2000 should give about 80% training accuracy and 67% test accuracy. Limitations of this model are that it uses only 2D filterbanks instead of 4D volumes. Further the model does not use any advanced CNN optimization techniques like Momentum or Dropout. Feel free to improve the model.
The Recurrent Neural Network is an 8 layer network. The purpose of this model is to learn adding two 8 bit binary digits. The Matlab code is re-implementation of the Python Code by Iamtrask. Like in the example above just run the file and you will able to see all variables and calculations in the Matlab workspace. If you like to dig deeper into the theory of this binary RNN, I recommend you to read this blog about binary RNN background info.
- Matlab: Just download the RNN folder and run
RNNtoymodel.min Matlab. - Python: Alternatively run the
RNNtoymodel.pyin Python.
Enjoy Roboball