{"id":17317918,"url":"https://github.com/marty1885/scirknn","last_synced_at":"2025-07-31T20:31:24.294Z","repository":{"id":180719115,"uuid":"665483883","full_name":"marty1885/scirknn","owner":"marty1885","description":"Convert and run scikit-learn MLPs on Rockchip NPU.","archived":false,"fork":false,"pushed_at":"2023-07-13T11:00:42.000Z","size":35,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-16T13:18:14.667Z","etag":null,"topics":["inference-acceleration","npu","rk3566","rk3588","rknn","rknpu2","rockchip","scikit-learn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marty1885.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-12T09:57:29.000Z","updated_at":"2024-04-03T17:40:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"e6684df7-de97-4ec5-a68d-9746466dc89e","html_url":"https://github.com/marty1885/scirknn","commit_stats":null,"previous_names":["marty1885/scirknn"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty1885%2Fscirknn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty1885%2Fscirknn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty1885%2Fscirknn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty1885%2Fscirknn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marty1885","download_url":"https://codeload.github.com/marty1885/scirknn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228296609,"owners_count":17897776,"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":["inference-acceleration","npu","rk3566","rk3588","rknn","rknpu2","rockchip","scikit-learn"],"created_at":"2024-10-15T13:18:14.298Z","updated_at":"2024-12-05T12:20:26.204Z","avatar_url":"https://github.com/marty1885.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scirknn\n\nUnholy but necessary code that converts scikit-learn's MLP classifer/regresser into RKNN2 files in order to run on Rockchip NPUs. Because `rknn-toolkit2` does not support the operations `sklearn-onnx` spits out. So you can put your busness logic on the edge (or other things you want to do). Also works around a ton of stuff that ONNX and rknn-toolkit2 expects the other party to solve.\n\nFor real, who is training models large enough to need a NPU on sklearn?\n\n## How it works\n\n* Grabs weights from the sklearn model\n* Build ONNX graph with nodes that RKNN accepts\n* Move operations RKNN does not support into Python (these are lite operations)\n* Convert ONNX into RKNN\n* Provides a lite Python wrapper with the same API as scikit-learn if you need it\n\n### Example\n\n```python\nfrom sklearn.neural_network import MLPClassifier\nimport sklearn2rknn # Convers scikit models into RKNN \n\n# obtain a MLP model \nx = [[0., 0.], [1., 1.], [2., 2.], [3., 3.]]\ny = [0, 1, 2, 3]\nclf = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(32, 32), random_state=1)\nclf.fit(x, y)\n\n# Convert and save the model targeting the RK3588 chip. If successful, this step produces\n# two files. `example.rknn` and `example.rknn.json`. The latter is metadata that is used\n# by wrappers later\nsklearn2rknn.convert(clf, \"example.rknn\", \"rk3588\", quantization=True, example_input=x)\n\n```\nOr, use the commandline.\n\n```bash\npython -m sklearn2rknn model.pkl model.rknn --quantization --example_input /path/to/data.npy\n\n```\n\nNow, copy `example.rknn` and `example.rknn.json` to your development board.\n\n```python\nimport scirknn # Wrapper to provide easy to use API\nmodel = scirknn.MLPClassifier(\"example.krnn\")\npred = model.predict([0, 0])\nprint(pred) # [0]\n```\n\n## Install\n\n* Install [rknn-toolkit2][rknn-toolkit-whl] from the official `.whl` file\n* Install the remaining dependencies `pip install -r requirments`\n  * only needed for model conversion\n\n[rknn-toolkit-whl]: https://github.com/rockchip-linux/rknn-toolkit2/tree/master/packages\n\nOn your dev board. Install [rknn-toolkit-lite][rknn-tookit-lite-whl] and put the correspending [librknnrt.so][rknnrt] in `/usr/lib`\n\n[rknn-tookit-lite-whl]: https://github.com/rockchip-linux/rknn-toolkit2/tree/master/rknn_toolkit_lite2/packages\n[rknnrt]: https://github.com/rockchip-linux/rknpu2/tree/master/runtime\n\n\n## Running the examples\n\nThe examples are stored in the `examples` folder. Every example has 2 files. `train.py` which trains a MLP model and coverts it into RKNN format. By default the training scripts converts for RK3588. And `infer.py` which shold run on the terget device. To run them, invoke them as a module.\n\n```bash\n\u003e python -m example.xor.train\n```\n\nThis prduces `xor.rknn` and `xor.rknn.json` in the current working directory. Copy them to your target device. Then run the following command to infer\n\n```bash\n\u003e ls xor.rknn*\nxor.rknn  xor.rknn.json\n\n\u003e python -m example.xor.infer\nI RKNN: [14:45:42.681] RKNN Runtime Information: librknnrt version: 1.5.0 (e6fe0c678@2023-05-25T08:09:20)\n...\n[1]\n```\nThe final line is the output!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty1885%2Fscirknn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarty1885%2Fscirknn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty1885%2Fscirknn/lists"}