ONNX Protobuf Definitions for JavaScript

8.0.1 · active · verified Sun Apr 19

This `onnx-proto` package provides pre-compiled Protobuf definitions for the Open Neural Network Exchange (ONNX) format, specifically derived from the upstream `onnx/onnx.proto3` file. It enables JavaScript and TypeScript projects to interact with ONNX models by offering type-safe access to the ONNX IR (Intermediate Representation) structures, encompassing messages like `ModelProto`, `GraphProto`, `NodeProto`, and `TensorProto`. The current stable version is 8.0.1, reflecting the latest ONNX IR_VERSION 8 (corresponding to ONNX v1.10.2). Releases are automatically published to npm from the master branch whenever the underlying ONNX definition is updated or significant maintenance occurs, ensuring developers have timely access to the latest ONNX specification. Its key differentiator is being a direct, pre-compiled, and type-safe representation of the official ONNX protobuf schema, saving users the complexity of generating Protobuf code themselves for JavaScript and TypeScript environments.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the `onnx` namespace and construct a basic `TensorProto` using its static `create` method, illustrating the package's utility for creating ONNX data structures.

import { onnx } from 'onnx-proto';

// Create a simple ONNX TensorProto object
const tensorProto = onnx.TensorProto.create({
  dims: [2, 2],
  dataType: onnx.TensorProto.DataType.FLOAT,
  floatData: [1.0, 2.0, 3.0, 4.0]
});

console.log('Created ONNX TensorProto:');
console.log(JSON.stringify(tensorProto.toJSON(), null, 2));

// Access an enum value from the ONNX definition
const floatDataType = onnx.TensorProto.DataType.FLOAT;
console.log(`\nONNX TensorProto.DataType.FLOAT value: ${floatDataType}`);

// This package provides type definitions and constructors for ONNX structures.
// It does not include an ONNX runtime. For model inference, a separate
// runtime library (e.g., onnxruntime-web) is required.

view raw JSON →