This project is my attempt to create a simple neural network framework in C++ (cpp17) that is powerful enough to give decent results in MNIST dataset in decent running time.
The project is inspired by the simplicity of Keras. e.g. creating a simple network for MNIST:
models::sequential m;
m.add("dense(units=300, input=784)");
m.add("dense(units=10)");
m.compile("loss=cross_entropy(), optimizer=sgd(learning_rate=0.5)");
m.summary();
Console Output:
See demo_mnist.cpp for full code.
Experiment:
- Dataset: MNIST
- Hidden Layers: 1 Dense Layer (300 neurons)
- Learning Rate: 0.5 (Decay = 0)
- Batch Size: 32
See demo_mnist.cpp for full code.
Here is a comparision of different Loss-Functions (test-accuracy)
Autoencoder Experiment:
- Dataset: MNIST
- Autoencoder (784->256->32, 32->256->784)
- Cross-entropy with Adam(learning_rate=0.001)
- Batch Size: 32
See autoencoder_mnist.cpp for full code.
Here is the reconstruction of some random examples.
git clone https://github.com/rahulsrma26/simpleNN.git
cd simpleNN
mkdir build
cd build
-
Linux and MacOS (make)
cmake .. make
-
Windows
Visual Studio 2017 and later can directly open a CMake project. However, if you want to build using Developer Command prompt and have cmake installed then run:
cmake .. msbuild simpleNN.sln /t:Build /p:Configuration=Release
# After build first download MNIST dataset
python ../scripts/download_mnist.py ../data/mnist
# or you can download fashion mnist
# python ../scripts/download_fashion.py ../data/fashion
# mnist example
bin/demo_mnist ../data/mnist
# spiral example
bin/spiral_test
# mnist model with save/restore
bin/mnist_model -h
For windows users who are using MSVC check '.exe' files in bin\Release folder.
You can also be build using ninja across any platform.
-
Using ninja
cmake .. -GNinja ninja -v
-
If you want to use mingw (GCC) instead of MSVC under windows then chocolatey can be used to install dependencies for ninja build.
choco intall -y mingw ninja cmake
After that append cmake install path ("C:\Program Files\CMake\bin") to Environment Variable.