What is onnxruntime-common?
The onnxruntime-common npm package provides common utilities and types for the ONNX Runtime JavaScript API. It is typically used in conjunction with other ONNX Runtime packages to facilitate the loading, running, and managing of ONNX models in JavaScript environments.
What are onnxruntime-common's main functionalities?
Model Management
This feature allows you to load an ONNX model into an inference session. The code sample demonstrates how to create an inference session from a model file.
const { InferenceSession } = require('onnxruntime-common');
async function loadModel(modelPath) {
const session = await InferenceSession.create(modelPath);
console.log('Model loaded successfully');
return session;
}
loadModel('path/to/model.onnx');
Inference
This feature allows you to run inference on an ONNX model. The code sample demonstrates how to create a tensor from input data, feed it into the model, and retrieve the inference results.
const { InferenceSession, Tensor } = require('onnxruntime-common');
async function runInference(session, inputData) {
const inputTensor = new Tensor('float32', inputData, [1, inputData.length]);
const feeds = { input: inputTensor };
const results = await session.run(feeds);
console.log('Inference results:', results);
return results;
}
(async () => {
const session = await InferenceSession.create('path/to/model.onnx');
const inputData = new Float32Array([1.0, 2.0, 3.0, 4.0]);
await runInference(session, inputData);
})();
Tensor Management
This feature allows you to create and manage tensors, which are the primary data structure used in ONNX models. The code sample demonstrates how to create a tensor from a data array and dimensions.
const { Tensor } = require('onnxruntime-common');
function createTensor(data, dims) {
const tensor = new Tensor('float32', data, dims);
console.log('Tensor created:', tensor);
return tensor;
}
const data = new Float32Array([1.0, 2.0, 3.0, 4.0]);
const dims = [2, 2];
createTensor(data, dims);
Other packages similar to onnxruntime-common
tensorflow
TensorFlow.js is a library for developing and training machine learning models in JavaScript. It provides a comprehensive set of tools for working with machine learning models, including model management, inference, and tensor operations. Compared to onnxruntime-common, TensorFlow.js offers a broader range of functionalities and is more widely used in the JavaScript machine learning community.
brain.js
Brain.js is a JavaScript library for neural networks. It provides simple and flexible APIs for creating, training, and running neural networks in JavaScript. While it does not support ONNX models, it offers an easy-to-use interface for building and deploying neural networks, making it a good alternative for simpler machine learning tasks.
synaptic
Synaptic is a JavaScript neural network library for node.js and the browser. It provides a modular and extensible framework for building and training neural networks. Although it does not support ONNX models, it offers a flexible and lightweight solution for neural network development in JavaScript.
ONNX Runtime JavaScript API
ONNX Runtime JavaScript API is a unified API for all JavaScript usages. It's dependency of the following NPM packages:
- onnxruntime-node
- onnxruntime-web
- onnxruntime-react-native
This package (onnxruntime-common) is not designed for using directly. Please consider to install one of the NPM packages above according to target platform.
License
License information can be found here.