jax-js
    Preparing search index...

    Class ONNXModel

    Loads an ONNX model (.onnx file) and provides a jax-js function that evaluates it.

    The returned function takes input tensors and returns output tensors. Input tensors are consumed (their reference count decremented). Initializers (model weights, data) are cached and reused across calls.

    import { ONNXModel } from "@jax-js/onnx";
    import { numpy as np } from "@jax-js/jax";

    const modelBytes = await fetch("./model.onnx").then((r) => r.bytes());
    const model = new ONNXModel(modelBytes);

    const input = np.ones([1, 3, 224, 224]);
    const { output } = model.run({ input });

    Constructors

    • Load a new model from binary contents of an .onnx file.

      Parameters

      • modelBytes: Uint8Array<ArrayBuffer>

      Returns ONNXModel

    Properties

    model: ModelProto

    The parsed model as a Protobuf object.

    run: (
        inputs: Record<string, np.Array>,
        options?: ONNXRunOptions,
    ) => Record<string, np.Array>

    Run a forward pass on the model. This function is bound to this, so you don't need to create a separate closure to pass it to transformations such as jit() and grad().

    Methods

    • Dispose of this model and free model weights.

      After disposing, run() should not be called anymore, it will not be able to find the missing variables.

      Returns void