Implementation:Microsoft Onnxruntime OnnxSequence
Appearance
| Knowledge Sources | Description |
|---|---|
| Source File | java/src/main/java/ai/onnxruntime/OnnxSequence.java |
| Repository | Microsoft/onnxruntime |
Domains
- Machine Learning Runtime
- Sequence Value Container
- JNI Native Interop
Overview
OnnxSequence represents a sequence of OnnxValue elements, all of the same type. It wraps a native ORT sequence value and can contain either a list of OnnxTensor objects (for String, Long, Float, or Double element types) or a list of OnnxMap objects (for map sequences). The class implements the OnnxValue interface.
Description
The class provides:
- Value extraction:
getValue()returns an unmodifiableList<? extends OnnxValue>. For map sequences, it calls the nativegetMapsmethod; for tensor sequences, it callsgetTensors. Unlike other OnnxValue.getValue() methods, this does not copy data to the Java heap -- it exposes native values as OnnxValue instances. The returned elements must be closed separately from the sequence. - Type info:
getInfo()returns theSequenceInfodescribing the element type. - Supported tensor element types: STRING, INT64, FLOAT, DOUBLE.
- Supported map types: Map<String, Float> and Map<Long, Float>.
- Lifecycle:
close()releases the native sequence;isClosed()checks state.
Code Reference
Source Location
// File: java/src/main/java/ai/onnxruntime/OnnxSequence.java
// Package: ai.onnxruntime
Signature
public class OnnxSequence implements OnnxValue {
public OnnxValueType getType(); // returns ONNX_TYPE_SEQUENCE
public List<? extends OnnxValue> getValue() throws OrtException;
public SequenceInfo getInfo();
public synchronized boolean isClosed();
public synchronized void close();
}
Import
import ai.onnxruntime.OnnxSequence;
I/O Contract
Inputs
| Name | Type | Description |
|---|---|---|
| nativeHandle | long | Pointer to the native ORT sequence value (set internally) |
| allocatorHandle | long | Pointer to the allocator |
| info | SequenceInfo | Type information about the sequence elements |
Outputs
| Name | Type | Description |
|---|---|---|
| getValue() | List<? extends OnnxValue> | Unmodifiable list of OnnxTensor or OnnxMap elements |
| getInfo() | SequenceInfo | Sequence element type metadata |
| getType() | OnnxValueType | Always ONNX_TYPE_SEQUENCE |
Usage Examples
import ai.onnxruntime.*;
import java.util.*;
OrtEnvironment env = OrtEnvironment.getEnvironment();
try (OrtSession session = env.createSession("/path/to/model.onnx")) {
Map<String, OnnxTensorLike> inputs = new HashMap<>();
// ... prepare inputs ...
try (OrtSession.Result results = session.run(inputs)) {
OnnxValue output = results.get(0);
if (output.getType() == OnnxValue.OnnxValueType.ONNX_TYPE_SEQUENCE) {
OnnxSequence sequence = (OnnxSequence) output;
List<? extends OnnxValue> elements = sequence.getValue();
System.out.println("Sequence length: " + elements.size());
for (OnnxValue element : elements) {
if (element instanceof OnnxTensor) {
System.out.println("Tensor value: " + ((OnnxTensor) element).getValue());
}
element.close(); // Elements must be closed separately
}
}
}
}
Related Pages
- SequenceInfo.java - Type metadata for OnnxSequence
- OnnxMap.java - Map type that can be contained in sequences
- OnnxTensor.java - Tensor type that can be contained in sequences
- OrtSession.java - Session that produces OnnxSequence outputs
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment