- This project implements a NN(Neural Network) to classify handwritten digits from the MNIST dataset.
- clone the project and add the sub-model(spdlog)
git clone https://github.com/Jungle430/NN_MNIST.git
git submodule init
git submodule update
- prepare the data
cd script
python3 read_mnist.py <train_data_set_size(0~60000)> <test_data_set_size(0~10000)>
-
You can safely set the scale of large datasets because the asynchronous data reading feature has been implemented. Therefore, you don't need to worry about memory overflow issues.
-
Set the scale of the neural network
NeuralNetwork<long double, 4> neural_network(
MNIST::IMAGE_DOMAIN, {{NN::DEFAULT_NODE_SIZE, "Sigmoid"},
{NN::DEFAULT_NODE_SIZE, "Sigmoid"},
{NN::DEFAULT_NODE_SIZE, "Sigmoid"},
{MNIST::NUMBER_SIZE, "Sigmoid"}});
-
The last layer is output layer, so the size must equal to kind of MNIST number(0~9)
-
Two active function can be chosen
- Sigmoid
- ReLU
-
The number of the layers must equal with N (
NeuralNetwork<dtype, N>
) -
make the program
mkdir build
cd build
cmake ..
make
- Then you can train and test your Neural Network Model!
- This neural network is written using C++'s STL library without any special optimizations, so its computational efficiency is much lower compared to PyTorch. The code for this neural network is primarily intended for understanding the structure of neural networks.
- network scale:
$3 \times 100$
- Remove irrelevant information from the log (like nohup), modify the log file path in
picture.py
, Then run the picture script
cd script
python3 picture.py
- Thanks the the open source project spdlog 1.14.1