{"id":20838079,"url":"https://github.com/timcsy/compugraph","last_synced_at":"2026-04-20T22:05:03.213Z","repository":{"id":187409649,"uuid":"483671016","full_name":"timcsy/CompuGraph","owner":"timcsy","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-07T07:30:05.000Z","size":701,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-18T23:15:01.965Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timcsy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-04-20T13:42:13.000Z","updated_at":"2022-06-02T09:14:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"e4b8e3ed-c50e-4fc4-be29-cced36d5f885","html_url":"https://github.com/timcsy/CompuGraph","commit_stats":null,"previous_names":["timcsy/compugraph"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timcsy%2FCompuGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timcsy%2FCompuGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timcsy%2FCompuGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timcsy%2FCompuGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timcsy","download_url":"https://codeload.github.com/timcsy/CompuGraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196571,"owners_count":20251853,"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":[],"created_at":"2024-11-18T01:09:20.226Z","updated_at":"2025-12-26T22:58:16.518Z","avatar_url":"https://github.com/timcsy.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CompuGraph - Simple Deep Learning Framework with Computational Graph\n\nAuthor: 張頌宇（timcsy）\n\nA simple C++ implementation of the deep learning framework using computational graph.\n\nIt's a simple version of TensorFlow, PyTorch, etc.\n\nIt provides python interface to pass data and receiving results, check `python/compugraph.cpp` for more information.\n\n## Requirements\nCMake (Please make sure you have install CMake!)\n\nPython 3\n\npybind11 - [Homepage](https://pybind11.readthedocs.io/en/latest/)\n\n\n## Setup\n\nFor Windows user, please install MinGW First!!!!\n\nMinGW for Windows 32 bit and 64 bit: https://www.mingw-w64.org/\n\nSuggest Download: https://github.com/mstorsjo/llvm-mingw/releases\n\nYou may have to install it at `C:\\MinGW` folder and add `C:\\MinGW\\bin` to your PATH environment variable.\n\n### Install as Python Package\nTo install as a Python package:\n```\ngit clone https://github.com/timcsy/CompuGraph.git\npip install ./CompuGraph\n```\n\n### Build Manually\nTo build for testing usage (or other scenarios):\n```\nmkdir build\ncd build\ncmake .. -DPYBIND11_PYTHON_VERSION=3.8\nmake\n```\nNote: The `3.8` part can change to the Python version you currently using.\n\nNote: Must install pybind11 first before building manually, or you can only build the library.\n\nIf you use MSVC to compile (not recommended), copy the `build/externel/bin/libopenblas.dll` to the same folder as the executable if needed (means you don't have OpenBLAS or any BLAS installed before).\n\n\n## Ussage\nIf you want to use pure C++ library, including files in the `inlcude` folder in the project root directory, and link with the library `build/src/libcg.a`\n\nCheck header files for more information about the API.\n\nRemember to call `Graph::initInstance();` in the beginning of your program, and call `Graph::deleteInstance();` at the end of your program.\n\nYou can see the samples in the `test` folder.\n\nIf you want to bind with Python, simply call `import compugraph`, use [pybind11](https://pybind11.readthedocs.io/en/latest/), check `python/compugraph.cpp` for more information. If you build manually, you can only import the package at the same location of the .so executable file, if you install as a Python package, you can import it anywhere.\n\nWhen building the graph, it is recommended to build the network structure before eveluating the graph, and not to build the graph again after eveluation, and it will cause unexpected behaviour. For example, compile the model first before fitting, and not to compile the same model again after fitting or evaluating.\n\n\n## Example - MNIST\nWe use MNIST for demo.\n\nBefore running the example, download [MNIST](http://yann.lecun.com/exdb/mnist/) data to `data` directory first.\n\nRun `python mnist_example.py` in the `examples` folder to see the result, and check `python/compugraph.cpp` for network information.\n\n### First Network\nNetwork:\n```\ninput: 784\nhidden layer: 128 (Activation function: LeakyRelu with parameter 0.01)\noutput layer: 10\nsoftmax\n\nLoss Function: Cross Entropy\n\nUsing Gradient Descent optimizer\nlearning rate: 0.01\n\nTraining data size: 60000\nTesting data size: 10000\nBatch size: 32\nEpochs: 10\nValidation split ratio: 0.2\n```\n\nResult (used time: about 53s):\n\nTraining (Accuracy: 0.9782)\n\n![](docs/imgs/train_1.png)\n\nValidation (Accuracy: 0.9579)\n\n![](docs/imgs/val_1.png)\n\nTesting (Accuracy: 0.9637)\n\nOutputs:\n```\nEpoch 1/10\n376/375 [==============================] - loss: 2.84888 - accuracy: 0.929019 - val_loss: 2.89861 - val_accuracy: 0.925487\nEpoch 2/10\n376/375 [==============================] - loss: 2.25355 - accuracy: 0.94949 - val_loss: 2.10567 - val_accuracy: 0.943968\nEpoch 3/10\n376/375 [==============================] - loss: 1.89424 - accuracy: 0.95864 - val_loss: 1.80724 - val_accuracy: 0.948925\nEpoch 4/10\n376/375 [==============================] - loss: 1.90859 - accuracy: 0.956509 - val_loss: 2.06167 - val_accuracy: 0.946909\nEpoch 5/10\n376/375 [==============================] - loss: 1.35808 - accuracy: 0.970296 - val_loss: 1.22512 - val_accuracy: 0.957913\nEpoch 6/10\n376/375 [==============================] - loss: 1.33307 - accuracy: 0.973826 - val_loss: 1.17582 - val_accuracy: 0.959677\nEpoch 7/10\n376/375 [==============================] - loss: 1.51062 - accuracy: 0.967183 - val_loss: 1.29992 - val_accuracy: 0.953965\nEpoch 8/10\n376/375 [==============================] - loss: 1.2688 - accuracy: 0.97485 - val_loss: 1.30519 - val_accuracy: 0.958165\nEpoch 9/10\n376/375 [==============================] - loss: 1.219 - accuracy: 0.977461 - val_loss: 1.08566 - val_accuracy: 0.96161\nEpoch 10/10\n376/375 [==============================] - loss: 1.15905 - accuracy: 0.978213 - val_loss: 0.954418 - val_accuracy: 0.957913\nTesting\n313/313 [==============================] - loss: 0.26099 - accuracy: 0.9637265\n```\n\n### Second Network\nNetwork:\n```\ninput: 784\nhidden layer: 128 (Activation function: LeakyRelu with parameter 0.01)\nhidden layer: 64 (Activation function: LeakyRelu with parameter 0.01)\noutput layer: 10\nsoftmax\n\nLoss Function: Cross Entropy\n\nUsing Gradient Descent optimizer\nlearning rate: 0.01\n\nTraining data size: 60000\nTesting data size: 10000\nBatch size: 32\nEpochs: 10\nValidation split ratio: 0.2\n```\n\nResult (used time: about 58s):\n\nTraining (Accuracy: 0.9729)\n\n![](docs/imgs/train_2.png)\n\nValidation (Accuracy: 0.9613)\n\n![](docs/imgs/val_2.png)\n\nTesting (Accuracy: 0.9606)\n\n\nOutputs:\n```\nEpoch 1/10\n376/375 [==============================] - loss: 2.24544 - accuracy: 0.865015 - val_loss: 2.25551 - val_accuracy: 0.862987\nEpoch 2/10\n376/375 [==============================] - loss: 2.868 - accuracy: 0.925259 - val_loss: 2.88714 - val_accuracy: 0.915827\nEpoch 3/10\n376/375 [==============================] - loss: 2.39219 - accuracy: 0.945793 - val_loss: 2.2763 - val_accuracy: 0.941364\nEpoch 4/10\n376/375 [==============================] - loss: 2.14042 - accuracy: 0.948926 - val_loss: 2.2506 - val_accuracy: 0.942036\nEpoch 5/10\n376/375 [==============================] - loss: 1.5262 - accuracy: 0.958995 - val_loss: 1.44461 - val_accuracy: 0.949933\nEpoch 6/10\n376/375 [==============================] - loss: 1.26316 - accuracy: 0.970421 - val_loss: 1.29571 - val_accuracy: 0.959005\nEpoch 7/10\n376/375 [==============================] - loss: 1.35879 - accuracy: 0.965888 - val_loss: 1.27213 - val_accuracy: 0.952117\nEpoch 8/10\n376/375 [==============================] - loss: 1.23391 - accuracy: 0.967288 - val_loss: 1.04896 - val_accuracy: 0.954637\nEpoch 9/10\n376/375 [==============================] - loss: 1.14298 - accuracy: 0.975017 - val_loss: 0.924099 - val_accuracy: 0.960433\nEpoch 10/10\n376/375 [==============================] - loss: 1.12197 - accuracy: 0.972949 - val_loss: 0.99669 - val_accuracy: 0.961358\nTesting\n313/313 [==============================] - loss: 0.275588 - accuracy: 0.960611\n```\n\n\n## More Information\nThe project is heavily based on [xtensor](https://github.com/xtensor-stack/xtensor), which is a NumPy-like library written in C++, check [docs](https://xtensor.readthedocs.io) for documentation, check [From numpy to xtensor](https://xtensor.readthedocs.io/en/latest/numpy.html) to see the corresponding NumPy functions, it's not support GPU now, but it supports SIMD CPU acceleration. We put xtensor library source code in the `lib` directory.\n\nThe project is inspired by [Deep Learning From Scratch: Theory and Implementation](https://www.codingame.com/playgrounds/9487/deep-learning-from-scratch---theory-and-implementation/computational-graphs), that's a really good way to learn about computational graph.\n\nThe project has implemented some operators defined in [ONNX - Operator Schemas](https://github.com/onnx/onnx/blob/main/docs/Operators.md), which is a API describing Neural Network. Check `include/node.h` for more information about the operators.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimcsy%2Fcompugraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimcsy%2Fcompugraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimcsy%2Fcompugraph/lists"}