This is a PyTorch-like neural network framework in pure C++ from scratch, using only C++ STL.
Currently supports:
More to come.
Current achievements: achieving 95% accuracy on MNIST.
Note
To support and foster the growth of the project, you could ⭐ star this project on GitHub. Discussion and suggestions are more welcome!
This project requires C++23, GCC >= 13.3, and CMake >= 3.20 to compile. Please make sure you have GCC and CMake installed.
For Mac OS, run the following commands:
brew install cmake
brew install gcc
For Linux, run the following commands:
sudo apt update
sudo apt install cmake
sudo apt install build-essential
Get the repository:
git clone https://github.com/lucaswychan/neuralnet-cpp.git
cd neuralnet-cpp
Build the project:
./build.sh
Run the example:
./main.sh
I implemented a tensor from scratch as well and integrate it to my neural network implementation. The detailed implementation of Tensor
can be found in include/core/tensor.hpp
.
For more details about tensor, please refer to tensor tutorial.
The module API is defined in include/core/module.hpp
.
To build your custom module, follow the instructions in include/core/module.hpp
.
#include <module.hpp>
using namespace nn;
// Your code here
class MyModule : public Module {
public:
virtual Tensor<> forward(const Tensor<>& input) override {
// Your code here
}
virtual Tensor<> backward(const Tensor<>& grad_output) override {
// Your code here
}
virtual void update_params(const float lr) override {
// Your code here
}
};
Please refer to the TODO list.
This project is licensed under the MIT License - see the LICENSE file for details.