Implementation:Microsoft Onnxruntime OnnxModelMetadata
Appearance
| Knowledge Sources | Description |
|---|---|
| Source File | java/src/main/java/ai/onnxruntime/OnnxModelMetadata.java |
| Repository | Microsoft/onnxruntime |
Domains
- Machine Learning Runtime
- Model Metadata
Overview
OnnxModelMetadata is a final class that contains the metadata associated with an ONNX model, including the producer name, graph name, graph description, domain, description, version, and custom key-value metadata. It is a pure Java-side copy of the native metadata and does not retain access to the native runtime after construction.
Description
The class provides read-only access to:
- producerName: The name of the tool that produced the model.
- graphName: The name of the model graph.
- graphDescription: A description of the model graph.
- domain: The model domain (e.g., "ai.onnx").
- description: A description of the model.
- version: The model version as a long.
- customMetadata: An unmodifiable
Map<String, String>of arbitrary key-value pairs.getCustomMetadataValue(String)returnsOptional<String>.
The class supports copy construction, equals/hashCode, and toString. All null fields are replaced with empty strings during construction.
Code Reference
Source Location
// File: java/src/main/java/ai/onnxruntime/OnnxModelMetadata.java
// Package: ai.onnxruntime
Signature
public final class OnnxModelMetadata {
public OnnxModelMetadata(OnnxModelMetadata other); // copy constructor
public String getProducerName();
public String getGraphName();
public String getGraphDescription();
public String getDomain();
public String getDescription();
public long getVersion();
public Map<String, String> getCustomMetadata();
public Optional<String> getCustomMetadataValue(String key);
}
Import
import ai.onnxruntime.OnnxModelMetadata;
I/O Contract
Inputs
| Name | Type | Description |
|---|---|---|
| (constructed by OrtSession) | - | Built internally from native model metadata |
| key | String | Custom metadata key for lookup |
Outputs
| Name | Type | Description |
|---|---|---|
| getProducerName() | String | The model producer name |
| getGraphName() | String | The graph name |
| getVersion() | long | The model version |
| getCustomMetadata() | Map<String, String> | Unmodifiable map of custom metadata |
| getCustomMetadataValue(key) | Optional<String> | Value for the given custom metadata key |
Usage Examples
import ai.onnxruntime.*;
import java.util.*;
OrtEnvironment env = OrtEnvironment.getEnvironment();
try (OrtSession session = env.createSession("/path/to/model.onnx")) {
OnnxModelMetadata metadata = session.getMetadata();
System.out.println("Producer: " + metadata.getProducerName());
System.out.println("Graph: " + metadata.getGraphName());
System.out.println("Domain: " + metadata.getDomain());
System.out.println("Description: " + metadata.getDescription());
System.out.println("Version: " + metadata.getVersion());
Map<String, String> customMeta = metadata.getCustomMetadata();
for (Map.Entry<String, String> entry : customMeta.entrySet()) {
System.out.println(" " + entry.getKey() + " = " + entry.getValue());
}
Optional<String> author = metadata.getCustomMetadataValue("author");
author.ifPresent(a -> System.out.println("Author: " + a));
}
Related Pages
- OrtSession.java - Provides access to model metadata via getMetadata()
- ai_onnxruntime_OrtSession.c - Native constructMetadata implementation
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment