This project shows how to generate and train a series of handwritten digit classifiers in Python and deploy a final model (99% accuracy) in iOS. For more info on the training procedure and results see this post.
The project is divided into 2 parts:
- Models were generated for a combination of hyper parameters and topologies and trained on the MNIST dataset.
- The best 5 models were kept and tested both on a portion of the MNIST test set as well as custom images.
- A final model was chosen out of the 5 to deploy to iOS.
Due to space considerations, the project only contains the final model, along with stats for the whole training session of all models.
Contents:
digits.py
: the entry point for training and testing.training.py
: the training algorithm, including topology + hyperparameter search.testing.py
: testing algorithms for both MNIST as well as custom images, including OpenCV code to preprocess custom images.statsplot.py
: plotting of training statistics.- data: the MNIST dataset plus custom images used in testing.
- training: a copy of the the final model and training stats from the session in which the final model as well as many others were generated.
An iOS app was implemented to take photographs, preprocess them and run the trained model on them to predict digits.
Contents:
ViewController
: Manages both the UI of the app and an instance ofNNModel
to do all preprocessing and prediction.NNModel
: The iOS-side model, written in Objective-C++ to interoperate between Cocoa, OpenCV and the trained model.nn.hpp
,arithmetic.hpp
,activation.hpp
: C++ implementation of subset of NNKit (originally written in Python), necessary to use the trained model in iOS.- 3rdparty: C++ libraries used by the NNKit C++ subset.
- Numpy
- NNKit
- OpenCV (if you want to preprocess custom images before testing).
- matplotlib (if you want to plot training stats).
- Eigen (header only, included in project).
- JSON for Modern C++ (header only, included in project).
- OpenCV (iOS framework only).
- XCode
After downloading or cloning the repo:
- Python: just
pip install -r requirements.txt
- iOS / Xcode: download the OpenCV framework and link against it in the Xcode project.