This is a simple implementation of backpropagation in Python. It is intended to be used as a learning tool, not as a production-ready neural network library.
Demo task: classify digits in the image.
-
Python 3.6+
-
Install
requirements.txt
pip install -r requirements.txt
See model.py
__call__
method for the implementation of backpropagation.
-
python train.py
to train a network on the digits recognition task. Model will be saved tomodel.pkl
file. -
python test.py
to test the network on the images in the./examples
directory.
-
The
dataloader
module contains a class for randomly generating data for the digits recognition task. -
Each batch contain
batch_size
images ofshape
(25 x 25). -
The images are generated by randomly placing a digit from 0 to 9 on a 25 x 25 random noise image.
-
The labels are vectors of length
batch_size
.
0.png | 1.png | 2.png | 3.png | 4.png |
---|---|---|---|---|
python test.py
output:
loading model from: ./model.pkl
image: examples/0.png, prediction: [2]
image: examples/1.png, prediction: [6]
image: examples/2.png, prediction: [0]
image: examples/3.png, prediction: [7]
image: examples/4.png, prediction: [4]