r/learnmachinelearning
•
u/elevenMiles11
•
17d ago
•
1
Project I built a handwritten digit recognizer Neural Network completely from scratch in C++ (No Python, No ML Libraries, Custom Matrix Math)
Hey everyone,
I wanted to truly understand the math and mechanics behind neural networks without relying on black box frameworks. So, I decided to build a handwritten digit recognizer from the ground up using C++20.
What I built:
- Custom Dataset (No MNIST): Instead of using MNIST, I hand-drew 1000 digit samples (20×20 pixels) one by one to build my own custom CSV dataset for training and testing.
- Implemented my own
Matrixclass from scratch to handle dot products, transpositions, and element-wise operations. - A Feed-Forward Network using Sigmoid activations. No biases, just weights initialized with Xavier/Glorot normal distribution.
- Implemented backpropagation and stochastic gradient descent manually.
- I built an interactive ASCII canvas using the Win32 API. You can draw a digit directly in the terminal with your mouse, hit space, and watch the network guess it in real-time.
Here is the GitHub repo if you want to check out:
https://github.com/elevenMiles/digit-recognizer-cpp
I'd love any feedback on the math, the architecture, or the C++ implementation!
12
u/BrilliantAntique963 17d ago
Where did you learn how to do it? I'm among those who wants to build things from scratch too. And kinda dislike shortcuts and pre built libraries. So... What would suggest if anything, to a learner
2
u/DadAndDominant 17d ago
Nice!
2
u/AddictedAcid 17d ago
so good man. love it!
2
u/captain_obvious_here 17d ago
Just wondering: Does your code analyze the way the drawing is done (starting point, directions, ending point), or only the finished drawing?
2
u/anadalg 16d ago
A few years ago I did the same.
Video: https://youtu.be/oCElhUzadaA
Source code: https://github.com/albertnadal/Tensar
2
u/Fun_Recording_6485 11d ago
This is awesome. I’m jealous lowkey.