{"id":18026360,"url":"https://github.com/FrozenAssassine/NeuralNetwork-Arduino","last_synced_at":"2025-03-27T01:31:09.741Z","repository":{"id":258983293,"uuid":"861327401","full_name":"FrozenAssassine/NeuralNetwork-Arduino","owner":"FrozenAssassine","description":"A lightweight neural network library for ESP32 and Arduino, enabling on-device training and simple predictions like XOR. Ideal for microcontroller-based AI projects with resource constraints. 🔧🚀","archived":false,"fork":false,"pushed_at":"2025-03-05T10:26:25.000Z","size":344,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T21:04:47.386Z","etag":null,"topics":["ai","arduino","cpp","esp32","local","neural-network","neural-networks","xor"],"latest_commit_sha":null,"homepage":"https://medium.com/@FrozenAssassine/neural-network-from-scratch-on-esp32-2a53a7b65f9f","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FrozenAssassine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-22T15:51:46.000Z","updated_at":"2025-03-05T10:25:49.000Z","dependencies_parsed_at":"2024-10-22T11:14:54.908Z","dependency_job_id":null,"html_url":"https://github.com/FrozenAssassine/NeuralNetwork-Arduino","commit_stats":null,"previous_names":["frozenassassine/neuralnetworkarduino","frozenassassine/neuralnetwork-arduino"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrozenAssassine%2FNeuralNetwork-Arduino","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrozenAssassine%2FNeuralNetwork-Arduino/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrozenAssassine%2FNeuralNetwork-Arduino/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrozenAssassine%2FNeuralNetwork-Arduino/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FrozenAssassine","download_url":"https://codeload.github.com/FrozenAssassine/NeuralNetwork-Arduino/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245764638,"owners_count":20668454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","arduino","cpp","esp32","local","neural-network","neural-networks","xor"],"created_at":"2024-10-30T08:06:16.605Z","updated_at":"2025-03-27T01:31:09.735Z","avatar_url":"https://github.com/FrozenAssassine.png","language":"C++","readme":"\u003c!--\u003cp align=\"center\"\u003e\n    \u003cimg src=\"path_to_your_logo\" height=\"150px\" width=\"auto\" alt=\"Neural Network Logo\"\u003e\n\u003c/p\u003e\n--\u003e\n\n\u003ch1 align=\"center\"\u003eNeural Network for ESP32 and Arduino\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/stars/FrozenAssassine/NeuralNetworkArduino?style=flat\"/\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues-pr/FrozenAssassine/NeuralNetworkArduino?style=flat\"/\u003e\n    \u003cimg src=\"https://img.shields.io/github/repo-size/FrozenAssassine/NeuralNetworkArduino?style=flat\"/\u003e\n\u003c/div\u003e\n\n## 🤔 What is this project?\n\nThis project is a lightweight neural network implementation designed to run on microcontrollers like the **ESP32** and **Arduino**. It demonstrates how even resource-constrained devices can train and perform simple tasks like **XOR** prediction. Maybe you’ll find a use case for simple robot projects.\n\nWhile it takes just some **seconds** to train on the ESP32, the Arduino requires significantly more time due to limited processing power.\n\n## 📎 [Blog to this project](https://medium.com/@FrozenAssassine/neural-network-from-scratch-on-esp32-2a53a7b65f9f)\n\n## 🛠️ Features\n- **On-device training**: Train your neural network directly on ESP32 or Arduino.\n- **XOR**: Predict simple numbers like in xor.\n- **Activation Functions**: Use activation functions like Sigmoid, Relu, Softmax, TanH and LeakyRelu\n- **Fast Training**: The ESP32 can train in just a few seconds, while the Arduino requires longer due to its slow processor.\n- **Xavier Initialization**: Optimizes weight distribution for faster training.\n## 🔮 Future features\n- Train on PC and load weights to chip\n- Save and load weights\n- More layer types\n\n## 🚀 Performance\n- ESP32: Fast training (~seconds).\n- Arduino: Slower training (~minutes or more).\n\n## 🫶 Code considerations\nI tried to keep the code as simple and easy to understand as possible. The neural network is completely built using OOP principles, which means that everything is its own class. This is useful for structuring the model later.\nFor the individual layers, I used the basic principle of inheritance, where I have a BaseLayer class and each layer inherits from it. The BaseLayer also implements some functions, like Train and FeedForward, as well as pointers to the weights, values, biases, and errors. In my inherited classes, I only have to override these functions with the training logic and variable implementations. This is very useful when adding new layers.\n\n## 🏗️ How to Use\n\n1. Clone this repository and open the project in Arduino IDE.\n2. Upload the code to your ESP32 or Arduino using Arduino IDE\n3. Monitor the predictions via Serial Monitor at 115200 baud rate.\n\nHere is an example code:\n\n```cpp\n#include \"Layers.h\"\n#include \"NeuralNetwork.h\"\n\nvoid setup() {\n  Serial.begin(115200);\n\n  NeuralNetwork *nn = new NeuralNetwork(3);\n  nn-\u003eStackLayer(new InputLayer(2));\n  nn-\u003eStackLayer(new DenseLayer(4, ActivationKind::TanH));\n  nn-\u003eStackLayer(new OutputLayer(1, ActivationKind::Sigmoid));\n  nn-\u003eBuild();\n\n  float inputs[4][2] = { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } };\n  float desired[4][1] = { { 0 }, { 1 }, { 1 }, { 0 } };\n\n  nn-\u003eTrain((float*)inputs, (float*)desired, 4, 2, 600, 0.1f);\n\n  // Predict XOR results:\n  for (int i = 0; i \u003c 4; i++) {\n    float *pred = nn-\u003ePredict(inputs[i], 2);\n    Serial.print(\"PREDICTION \");\n    Serial.print(inputs[i][0]);\n    Serial.print(\" \");\n    Serial.print(inputs[i][1]);\n    Serial.print(\" = \");\n    Serial.println(pred[0]);\n  }\n}\n\nvoid loop() {\n  delay(1000);\n}\n```\n\n# 📷 Images:\n![image](https://github.com/user-attachments/assets/4b32f9ee-a1e9-4b4f-b626-1c4d5d9a3861)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFrozenAssassine%2FNeuralNetwork-Arduino","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFrozenAssassine%2FNeuralNetwork-Arduino","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFrozenAssassine%2FNeuralNetwork-Arduino/lists"}