{"id":13341505,"url":"https://github.com/izzat5233/fruit-classifier-wasm","last_synced_at":"2025-03-11T22:31:02.286Z","repository":{"id":211105572,"uuid":"722778187","full_name":"izzat5233/fruit-classifier-wasm","owner":"izzat5233","description":"Artificial Neural Network in Web Assembly, C++ Core \u0026 Interactive Website.","archived":false,"fork":false,"pushed_at":"2024-04-19T20:40:32.000Z","size":301,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-24T10:06:15.001Z","etag":null,"topics":["artificial-neural-networks","classification","cmake","cpp","d3js","data-visualization","emscripten","fruit-recognition","github-actions","hugo","machine-learning","web-assembly"],"latest_commit_sha":null,"homepage":"https://izzat5233.github.io/fruit-classifier-wasm/","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/izzat5233.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":"2023-11-23T23:44:12.000Z","updated_at":"2024-04-19T20:40:36.000Z","dependencies_parsed_at":"2023-12-26T00:28:58.717Z","dependency_job_id":"63dde970-c449-4e02-8f35-65a5aca68ab7","html_url":"https://github.com/izzat5233/fruit-classifier-wasm","commit_stats":null,"previous_names":["izzat5233/fruit-classifier-wasm"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzat5233%2Ffruit-classifier-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzat5233%2Ffruit-classifier-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzat5233%2Ffruit-classifier-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzat5233%2Ffruit-classifier-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzat5233","download_url":"https://codeload.github.com/izzat5233/fruit-classifier-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243125087,"owners_count":20240263,"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":["artificial-neural-networks","classification","cmake","cpp","d3js","data-visualization","emscripten","fruit-recognition","github-actions","hugo","machine-learning","web-assembly"],"created_at":"2024-07-29T19:25:28.803Z","updated_at":"2025-03-11T22:31:01.860Z","avatar_url":"https://github.com/izzat5233.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fruism | Classifier Neural Network in WASM\n\nInteractive general puposes, web-based, neural network written in C++ \u0026 Web Assembly.\nIt's fast and runs directly on your device.\n\n## Features:\n\n- *Web Based*: Although written in low level C++, it's integrated in the web and run directly on your local device using web assembly.\n- *Customizable Neural Network*: Create neural networks with varying structures, including different numbers of layers,\n  neurons per layer, and activation functions.\n- *Multiple Activation Functions*: Includes several built-in activation functions like step, sign, linear, ReLU,\n  sigmoid,\n  and tanh, each with its corresponding derivative for backpropagation.\n- *Efficient Computation*: Optimized for performance, utilizes WebAssembly to allow fast c++ near-native speed.\n- *Gradient Descent Training*: Utilizes gradient descent algorithm for network training.\n\n## Core Library\n\n- **[```nn```](nn/nn.h)**: Main namespace containing all components.\n  Check [this](nn/nn.h) header for documentation.\n\n- **[```Neuron```](nn/neuron.h)**: Represents a single neuron, encapsulating weights and bias.\n  Provides functionality for computing neuron's output.\n\n- **Layer Types**:\n    - **[```Layer```](nn/layer.h)**: Base class for layers in the neural network.\n    - **[```HiddenLayer```](nn/hidden_layer.h)**: Represents a hidden layer in the network.\n    - **[```OutputLayer```](nn/output_layer.h)**: Special layer type using Softmax activation.\n\n- **[```Network```](nn/network.h)**:Represents the entire neural network, a collection of layers.\n  Implements forward and backward propagation methods for network training.\n\n- **Activation Functions**: Defined in the ```act``` namespace with built-in functions for use in network layers.\n  Includes a special softmax function for output layers.\n\n- **Loss Functions**: Defined in the ```loss``` namespace with built-in functions for use in network layers.\n\n- **Factory Functions**:\n  Located in the ```make``` namespace, these functions allow for the creation of Neurons, Layers, and Networks with\n  specific configurations.\n\n### Usage\n\n- To create a neural network:\n    - Define Network Structure: Determine the number of layers and neurons in each layer.\n    - Select Activation Functions: Choose activation functions for each hidden layer.\n    - Create Network: Use the ```nn::make::network``` function to create a network instance.\n    - Train the Network: Provide training data and use ```nn::Network::train``` method to train the network.\n\n- Example\n\n```c++\n#include \u003cnetwork.h\u003e\n\nint main() {\n    // Create a neural network with specific dimensions and activation functions\n    // The following network has 2 inputs and a hidden layers with 2 neurons,\n    // and output layer with 2 neurons. With an initial learning rate of 0.01.\n    // First hidden layer uses ReLU activation function, second one uses Sigmoid.\n    nn::Network network = nn::make::network({2, 2, 2}, {nn::act::relu, nn::act::sigmoid}, 0.01);\n\n    // Define the data. Typically, a vector of decimals vectors.\n    nn::vpvd_t data = {       // This is an XOR dataset\n            {{0, 0}, {1, 0}}, // for 0 xor 0 we expect a 0\n            {{0, 1}, {0, 1}}, // for 0 xor 1 we expect a 1\n            {{1, 0}, {0, 1}}, // for 1 xor 0 we expect a 1\n            {{1, 1}, {1, 0}}  // for 1 xor 1 we expect a 0\n    };\n    \n    // Train the network with your data...\n    // Keep training until it reaches 100 epochs\n    // or a maximum sum square error 0.1\n    for (std::size_t i = 0; i \u003c 100; ++i) {\n        auto error = network.train(data, nn::loss::sse);\n        if (error \u003c= 0.1) { break; }\n    }\n    \n\n    // Now use it to predict outputs...\n    // vd_t is a vector of double values.\n    // example result {0.129248 0.870752}\n    nn::vd_t output = network.predict({0, 1});\n    \n    return 0;\n}\n```\n\n### Development\n\nTo get started with development:\n\n1. **Emscripten Installation**: Make sure Emscripten is installed and properly configured on your system. Follow the\n   installation guide on the official [Emscripten website](https://emscripten.org/docs/getting_started/downloads.html).\n\n2. **Configure Build Profiles**:\n    - **Release Profile**: For building the final WebAssembly version of the project, use the Release profile. This\n      includes Emscripten's toolchain for WebAssembly compilation. Compiled wasm files will be located\n      at `/web/static/wasm`\n      afterward to be used by hugo server.\n        ```sh\n        cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=path/to/emscripten/cmake/Modules/Platform/Emscripten.cmake -B build/release -S .\n        ```\n    - **Debug Profile**: For development and testing, use the Debug profile. This profile is configured to run all the\n      tests in the `test` directory.\n        ```sh\n        cmake -DCMAKE_BUILD_TYPE=Debug -B build/debug -S .\n        ```\n\n3. **Build the Project**:\n    - Navigate to the appropriate build directory (`build/debug` or `build/release`) and build the project:\n        ```sh\n        cmake --build .\n        ```\n\n4. **Run Tests** (Debug profile only):\n    - In the Debug profile, execute the tests to ensure everything is functioning correctly:\n        ```sh\n        ctest\n        ```\n\n5. **Web Integration** (Release profile only):\n    - For the Release profile, include the generated JavaScript and WebAssembly files in your web project. Use the\n      Emscripten Module API for interaction with the compiled code.\n    - All wasm files are generated at `/web/static/wasm`. `web/static` directory is served as-is by hugo server.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzat5233%2Ffruit-classifier-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzat5233%2Ffruit-classifier-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzat5233%2Ffruit-classifier-wasm/lists"}