Installations
npm install onnxjs
Developer Guide
Typescript
Yes
Module System
CommonJS, UMD
Node Version
12.18.0
NPM Version
6.14.4
Score
58.5
Supply Chain
99.3
Quality
74
Maintenance
100
Vulnerability
98.2
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (93%)
C++ (4.22%)
JavaScript (2.34%)
C (0.44%)
PureBasic (0.01%)
Developer
Microsoft
Download Statistics
Total Downloads
234,506
Last Day
41
Last Week
876
Last Month
4,589
Last Year
67,208
GitHub Statistics
1,774 Stars
148 Commits
127 Forks
39 Watching
31 Branches
10,000 Contributors
Package Meta Information
Latest Version
0.1.8
Package Id
onnxjs@0.1.8
Unpacked Size
3.48 MB
Size
745.94 kB
File Count
484
NPM Version
6.14.4
Node Version
12.18.0
Total Downloads
Cumulative downloads
Total Downloads
234,506
Last day
-77.6%
41
Compared to previous day
Last week
-17.7%
876
Compared to previous week
Last month
-10.4%
4,589
Compared to previous month
Last year
43.2%
67,208
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
45
ONNX.js
ONNX.js is a Javascript library for running ONNX models on browsers and on Node.js.
ONNX.js has adopted WebAssembly and WebGL technologies for providing an optimized ONNX model inference runtime for both CPUs and GPUs.
Why ONNX models
The Open Neural Network Exchange (ONNX) is an open standard for representing machine learning models. The biggest advantage of ONNX is that it allows interoperability across different open source AI frameworks, which itself offers more flexibility for AI frameworks adoption. See Getting ONNX Models.
Why ONNX.js
With ONNX.js, web developers can score pre-trained ONNX models directly on browsers with various benefits of reducing server-client communication and protecting user privacy, as well as offering install-free and cross-platform in-browser ML experience.
ONNX.js can run on both CPU and GPU. For running on CPU, WebAssembly is adopted to execute the model at near-native speed. Furthermore, ONNX.js utilizes Web Workers to provide a "multi-threaded" environment to parallelize data processing. Empirical evaluation shows very promising performance gains on CPU by taking full advantage of WebAssembly and Web Workers. For running on GPUs, a popular standard for accessing GPU capabilities - WebGL is adopted. ONNX.js has further adopted several novel optimization techniques for reducing data transfer between CPU and GPU, as well as some techniques to reduce GPU processing cycles to further push the performance to the maximum.
See Compatibility and Operators Supported for a list of platforms and operators ONNX.js currently supports.
Benchmarks
Benchmarks have been run against the most prominent open source solutions in the same market. Below are the results collected for Chrome and Edge browsers on one sample machine (computations run on both CPU and GPU):
NOTE:
- Keras.js doesn't support WebGL usage on Edge
- Keras.js and TensorFlow.js don't support WebAssembly usage on any browser
The specs of the machine that was used to perform the benchmarking is listed below:
- OS: Microsoft Windows 10 Enterprise Insider Preview
- Model: HP Z240 Tower Workstation
- Processor: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz, 3401 Mhz, 4 Core(s), 8 Logical Processor(s)
- Installed Physical Memory (RAM): 32.0 GB
- GPU make / Chip type: AMD FirePro W2100 / AMD FirePro SDI (0x6608)
- GPU Memory (approx.): 18.0 GB
Demo
ONNX.js demo website shows the capabilities of ONNX.js. Check the code.
Getting Started
There are multiple ways to use ONNX.js in a project:
Using <script>
tag
This is the most straightforward way to use ONNX.js. The following HTML example shows how to use it:
1<html> 2 <head> </head> 3 4 <body> 5 <!-- Load ONNX.js --> 6 <script src="https://cdn.jsdelivr.net/npm/onnxjs/dist/onnx.min.js"></script> 7 <!-- Code that consume ONNX.js --> 8 <script> 9 // create a session 10 const myOnnxSession = new onnx.InferenceSession(); 11 // load the ONNX model file 12 myOnnxSession.loadModel("./my-model.onnx").then(() => { 13 // generate model input 14 const inferenceInputs = getInputs(); 15 // execute the model 16 myOnnxSession.run(inferenceInputs).then((output) => { 17 // consume the output 18 const outputTensor = output.values().next().value; 19 console.log(`model output tensor: ${outputTensor.data}.`); 20 }); 21 }); 22 </script> 23 </body> 24</html>
Refer to browser/Add for an example.
Using NPM and bundling tools
Modern browser based applications are usually built by frameworks like Angular, React, Vue.js and so on. This solution usually builds the source code into one or more bundle file(s). The following TypeScript example shows how to use ONNX.js in an async context:
- Import
Tensor
andInferenceSession
.
1import { Tensor, InferenceSession } from "onnxjs";
- Create an instance of
InferenceSession
.
1const session = new InferenceSession();
- Load the ONNX.js model
1// use the following in an async method 2const url = "./data/models/resnet/model.onnx"; 3await session.loadModel(url);
- Create your input Tensor(s) similar to the example below. You need to do any pre-processing required by your model at this stage. For that refer to the documentation of the model you have:
1// creating an array of input Tensors is the easiest way. For other options see the API documentation 2const inputs = [ 3 new Tensor(new Float32Array([1.0, 2.0, 3.0, 4.0]), "float32", [2, 2]), 4];
- Run the model with the input Tensors. The output Tensor(s) are available once the run operation is complete:
1// run this in an async method: 2const outputMap = await session.run(inputs); 3const outputTensor = outputMap.values().next().value;
More verbose examples on how to use ONNX.js are located under the examples
folder. For further info see Examples
Running in Node.js
ONNX.js can run in Node.js as well. This is usually for testing purpose. Use the require()
function to load ONNX.js:
1require("onnxjs");
You can also use NPM package onnxjs-node
, which offers a Node.js binding of ONNXRuntime.
1require("onnxjs-node");
See usage of onnxjs-node.
Refer to node/Add for a detailed example.
Documents
Developers
For information on ONNX.js development, please check Development
For API reference, please check API.
Getting ONNX models
You can get ONNX models easily in multiple ways:
- Choose a pre-trained ONNX model from the ONNX Model Zoo
- Convert models from mainstream frameworks, e.g. PyTorch, TensorFlow and Keras, by following ONNX tutorials
- Use your data to generate a customized ONNX model from Azure Custom Vision service
- Train a custom model in AzureML and save it in the ONNX format
Learn more about ONNX
Compatibility
Desktop Platforms
OS/Browser | Chrome | Edge | FireFox | Safari | Opera | Electron | Node.js |
---|---|---|---|---|---|---|---|
Windows 10 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
macOS | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Ubuntu LTS 18.04 | :heavy_check_mark: | - | :heavy_check_mark: | - | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Mobile Platforms
OS/Browser | Chrome | Edge | FireFox | Safari | Opera |
---|---|---|---|---|---|
iOS | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Android | :heavy_check_mark: | :heavy_check_mark: | Coming soon | - | :heavy_check_mark: |
Operators
ONNX.js currently supports most operators in ai.onnx operator set v7 (opset v7). See operators.md for a complete, detailed list of which ONNX operators are supported by the 3 available builtin backends (cpu, wasm, and webgl).
Support for ai.onnx.ml operators is coming soon. operators-ml.md has the most recent status of ai.onnx.ml operators.
Contribute
We’d love to embrace your contribution to ONNX.js. Please refer to CONTRIBUTING.md.
Thanks
Thanks to BrowserStack for providing cross browser testing support.
License
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/microsoft/.github/SECURITY.md:1
- Info: Found linked content: github.com/microsoft/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/microsoft/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/microsoft/.github/SECURITY.md:1
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
Found 22/26 approved changesets -- score normalized to 8
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
68 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-mpjm-v997-c4h4
- Warn: Project is vulnerable to: GHSA-3p22-ghq8-v749
- Warn: Project is vulnerable to: GHSA-77xc-hjv8-ww97
- Warn: Project is vulnerable to: GHSA-mq8j-3h7h-p8g7
- Warn: Project is vulnerable to: GHSA-p2jh-44qj-pf2v
- Warn: Project is vulnerable to: GHSA-p7v2-p9m8-qqg7
- Warn: Project is vulnerable to: GHSA-7x97-j373-85x5
- Warn: Project is vulnerable to: GHSA-7m48-wc93-9g85
- Warn: Project is vulnerable to: GHSA-qqvq-6xgj-jw8g
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-j4f2-536g-r55m
- Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c
- Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-wpg7-2c88-r8xv
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-78cj-fxph-m83p
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
Score
4.2
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to onnxjs
onnxjs-node
ONNXRuntime backend for ONNX.js
onnxjs-voka
A Javascript library for running ONNX models on browsers and on Node.js
onnxjs-tensor-checks-disabled
A Javascript library for running ONNX models on browsers and on Node.js
@s9y/onnxjs-dev
A Javascript library for running ONNX models on browsers and on Node.js