This project implements a mini neural network in C for classifying handwritten digits from the MNIST dataset.
- Two-layer neural network (input -> hidden -> output)
- ReLU activation for hidden layer
- Softmax activation for output layer
- Cross-entropy loss function
- Stochastic Gradient Descent (SGD) with momentum
- L2 regularization
- GCC compiler
- MNIST dataset files:
train-images.idx3-ubyte
train-labels.idx1-ubyte
gcc -o nn nn.c -lm
- Place the MNIST dataset files in the
data/
directory. - Compile the program.
- Run the executable:
./nn
The program will train the neural network on the MNIST dataset and output the accuracy and average loss for each epoch.
You can adjust the following parameters in nn.c
:
HIDDEN_SIZE
: Number of neurons in the hidden layerLEARNING_RATE
: Initial learning rateMOMENTUM
: Momentum coefficient for SGDL2_LAMBDA
: L2 regularization coefficientEPOCHS
: Number of training epochsBATCH_SIZE
: Mini-batch size for training
This project is open-source and available under the MIT License.