Welcome to the Handwriting Recognition project, an educational initiative to explore neural networks using the MNIST dataset in modern C++. This project demonstrates memory-safe programming practices and leverages state-of-the-art C++ features. For an in-depth look at the underlying memory models and safety mechanisms, check out my blog post on C++ memory models.
This project aims to:
- Familiarize with neural networks and handwriting recognition.
- Utilize modern C++ for enhanced performance and memory safety.
- Provide a modular and maintainable codebase that leverages best practices in C++.
The project uses the popular MNIST dataset to train and test a neural network that recognizes handwritten digits.
- Modern C++ Implementation: Built with modern C++ standards for robust and efficient code.
- Memory Safety: Focus on secure memory management and performance.
- Configurable Training: Easily adjustable parameters via a configuration file.
- OpenMP Support: Optional OpenMP support for enhanced parallelism during training.
This project uses CMake as its build system. Follow these steps to build the project:
-
Generate the Build Files
cmake -S . -B build -
Available Build Parameters
DCMAKE_BUILD_TYPE: Set the build type. Options:DebugorRelease(default:Release).DENABLE_VERBOSE: Enable verbose logging. Options:ONorOFF(default:OFF).DENABLE_OPENMP: Enable OpenMP support for parallel processing. Options:ONorOFF(default:ON).
-
Compile the Project
cmake --build build
To train and test the neural network, execute the compiled binary and provide a configuration file as an argument:
build/neural_network input.example.configThe configuration file specifies training parameters, paths to datasets, and other essential settings.
Below is an example configuration file (input.example.config):
num_epochs = 5
batch_size = 100
hidden_size = 500
learning_rate = 1E-3
rel_path_train_images = mnist-datasets/train-images.idx3-ubyte
rel_path_train_labels = mnist-datasets/train-labels.idx1-ubyte
rel_path_test_images = mnist-datasets/t10k-images.idx3-ubyte
rel_path_test_labels = mnist-datasets/t10k-labels.idx1-ubyte
rel_path_log_file = log_predictions.txtFeel free to adjust these parameters to experiment with different training configurations.
Contributions are welcome! If you have suggestions or improvements, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with clear commit messages.
- Open a pull request detailing your changes and the reasoning behind them.
This project is open-source. Please refer to the LICENSE file for more details.