Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Microsoft Onnxruntime Nodejs Output Processing

From Leeroopedia


Field Value
Principle Name Nodejs_Output_Processing
Overview Extraction of typed array data from output tensors returned by ONNX Runtime inference in Node.js.
Category API Doc
Domains ML_Inference, JavaScript_Integration
Source Repository microsoft/onnxruntime
Last Updated 2026-02-10

Overview

Extraction of typed array data from output tensors returned by ONNX Runtime inference in Node.js. After running inference, the output tensors contain the model's predictions in their underlying TypedArrays, which can be accessed for downstream processing such as classification, post-processing, or display.

Description

After inference, output tensors are accessed by name from the results object returned by session.run(). The results object is a Record<string, ort.Tensor> where each key is an output name defined in the ONNX model graph.

Each output tensor exposes several properties:

  • .data: Returns the underlying TypedArray (Float32Array, Int32Array, etc.) containing the raw output values.
  • .dims: Returns the shape of the output tensor as a number[] array.
  • .type: Returns the element type as a string (e.g., Template:'float32', Template:'int64').
  • .size: Returns the total number of elements in the tensor.

The .data property is the primary access point for extracting inference results. The returned TypedArray can be directly iterated, indexed, or passed to downstream processing functions. For multi-dimensional outputs, the data is stored in row-major (C-contiguous) order in the flat TypedArray, matching standard ONNX tensor layout conventions.

Common post-processing operations include:

  • Argmax: Finding the index of the maximum value for classification tasks.
  • Softmax: Converting logits to probabilities.
  • Thresholding: Converting continuous outputs to binary decisions.
  • Reshaping: Interpreting the flat buffer according to the tensor's dimensions.

Theoretical Basis

The output processing step bridges the gap between the mathematical tensor representation used internally by the ONNX Runtime engine and the JavaScript data structures needed by application code. The TypedArray interface provides efficient, typed access to the raw numerical output without data copying or boxing overhead.

Output tensor data follows ONNX's standard row-major memory layout, where the last dimension varies fastest. This is consistent with NumPy's default C-order and allows direct interpretation of multi-dimensional results from the flat buffer using standard index arithmetic: for a tensor with shape [d0, d1, d2], the element at position [i, j, k] is at flat index i * d1 * d2 + j * d2 + k.

Usage

Output processing is the final step in the Node.js inference pipeline:

  1. Execute session.run(feeds) to obtain the results object.
  2. Access the desired output tensor by name (e.g., results.outputName).
  3. Read the .data property to get the underlying TypedArray.
  4. Optionally inspect .dims and .type for shape and type information.
  5. Perform application-specific post-processing on the raw data.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment