neural-classifier
2024-10-12
Classification of samples based on neural network.
Upstream URL
Author
License
Neural-classifier
neural-classifier is a neural network library based on the first chapters
from this book. It is divided on
two systems: neural-classifier which is a general API for neural networks
and neural-classifier/mnist which contains helper functions for working with
MNIST/EMNIST datasets. For API documentation visit
this page.
How to work with MNIST dataset?
- Unpack files in
mnist/datasetdirectory. - Load
neural-classifier/mnistsystem:(ql:quickload :neural-classifier/mnist). - Eval
(neural-classifier-mnist:load-mnist-database)(this will take about 10-15 seconds). - Create a neural network:
(defparameter *nn* neural-classifier-mnist:make-mnist-classifier 35)where35is a number of hidden neurons. - Execute
(neural-classifier-mnist:train-epochs *nn* 10)to train the network for 10 epochs. This function will return data about the network's accuracy for each epoch. - To test your own digits convert them to
784x1matrix of typemagicl:matrix/single-floatand pass it toneural-classifier:calculatefunction.
How to build custom nets and data?
See GH pages for this project (link above). In general you need to write
functions which translate your data and labels into magicl:matrix/single-float
matrices. Then you create a net with neural-classifier:make-neural-network
function and snakes generator which returns conses in the form (DATA . LABEL). To train a network for one epoch you call
(neural-classifier:train-epoch).
Dependencies
blasandlapackforeign libraries.magiclfor matrix operations.nibblesfor loading MNIST data.
magicl and nibbles can be downloaded with quicklisp.
What if the network shows good accuracy but fails to recognize my own digits?
If the accuracy returned by train-epochs is good, but the network fails to
recognize digits draws by your own hand, try EMNIST database instead of
MNIST. Copy four emnist-digits-* files to your MNIST directory preserving
the name of destination files. Images in EMNIST set are transposed (x and y
coordinates swapped), so do the same with your own images.