Class NamedOnnxValue
This is a legacy class that is kept for backward compatibility. Use OrtValue based API.
The class associates a name with an Object. The name of the class is a misnomer, it does not hold any Onnx values, just managed representation of them.
The class is currently used as both inputs and outputs. Because it is non- disposable, it can not hold on to any native objects.
When used as input, we temporarily create OrtValues that map managed inputs directly. Thus we are able to avoid copying of contiguous data.
For outputs, tensor buffers works the same as input, providing it matches the expected output shape. For other types (maps and sequences) we create a copy of the data. This is because, the class is not Disposable and it is a public interface, thus it can not own the underlying OrtValues that must be destroyed before Run() returns.
To avoid data copying on output, use DisposableNamedOnnxValue class that is returned from Run() methods. This provides access to the native memory tensors and avoids copying.
It is a recursive structure that may contain Tensors (base case) Other sequences and maps. Although the OnnxValueType is exposed, the caller is supposed to know the actual data type contained.
The convention is that for tensors, it would contain a DenseTensor{T} instance or anything derived from Tensor{T}.
For sequences, it would contain a IList{T} where T is an instance of NamedOnnxValue that would contain a tensor or another type.
For Maps, it would contain a IDictionary{K, V} where K,V are primitive types or strings.
Inherited Members
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public class NamedOnnxValue
Constructors
| Improve this Doc View SourceNamedOnnxValue(String, Object)
Constructs an instance of NamedOnnxValue and represents a model input to an inference session.
Declaration
[Obsolete("Use constructors with valueType or static factory methods")]
protected NamedOnnxValue(string name, object value)
Parameters
Type | Name | Description |
---|---|---|
String | name | input/output name |
Object | value | Object that may be a tensor, Dictionary, IList |
Properties
| Improve this Doc View SourceName
Exposes the name of the of the model input/output
Declaration
public string Name { get; set; }
Property Value
Type | Description |
---|---|
String | name string |
Value
Exposes the underlying managed object
Declaration
public object Value { get; set; }
Property Value
Type | Description |
---|---|
Object | object |
ValueType
Onnx Value Type if known. In general, NamedOnnxValue is able to contain arbitrary objects. Please, follow the convention described in the class doc.
Declaration
public OnnxValueType ValueType { get; }
Property Value
Type | Description |
---|---|
OnnxValueType |
Methods
| Improve this Doc View SourceAsDictionary<K, V>()
Try-get value as an Dictionary<K,V>.
Declaration
public IDictionary<K, V> AsDictionary<K, V>()
Returns
Type | Description |
---|---|
IDictionary<K, V> | Dictionary object if contained value is a Dictionary. Null otherwise |
Type Parameters
Name | Description |
---|---|
K | Key type currently primitive type only |
V | Value type, currently primitive type only |
AsEnumerable<T>()
Try-get value as an Enumerable<T>. T is usually a NamedOnnxValue instance that may contain Tensors, Sequences, Maps or optional types
Declaration
public IEnumerable<T> AsEnumerable<T>()
Returns
Type | Description |
---|---|
IEnumerable<T> | Enumerable object if contained value is a Enumerable. Null otherwise |
Type Parameters
Name | Description |
---|---|
T | Type |
AsTensor<T>()
Try-get value as a Tensor<T>.
Declaration
public Tensor<T> AsTensor<T>()
Returns
Type | Description |
---|---|
Tensor<T> | Tensor object if contained value is a Tensor. Null otherwise |
Type Parameters
Name | Description |
---|---|
T | Type |
CreateFromMap<K, V>(String, IDictionary<K, V>)
Instantiates NamedOnnxValue that contains IDictionary{K, V}
Declaration
public static NamedOnnxValue CreateFromMap<K, V>(string name, IDictionary<K, V> value)
Parameters
Type | Name | Description |
---|---|---|
String | name | |
IDictionary<K, V> | value |
Returns
Type | Description |
---|---|
NamedOnnxValue | new instance of NamedOnnxValue |
Type Parameters
Name | Description |
---|---|
K | Keys type |
V | Values type |
CreateFromSequence<T>(String, IEnumerable<T>)
This is a factory method that instantiates NamedOnnxValue. It would contain a sequence of elements
Declaration
public static NamedOnnxValue CreateFromSequence<T>(string name, IEnumerable<T> value)
Parameters
Type | Name | Description |
---|---|---|
String | name | |
IEnumerable<T> | value |
Returns
Type | Description |
---|---|
NamedOnnxValue |
Type Parameters
Name | Description |
---|---|
T |
CreateFromTensor<T>(String, Tensor<T>)
This is a factory method that instantiates NamedOnnxValue
and associated name with an instance of a TensorT
Declaration
public static NamedOnnxValue CreateFromTensor<T>(string name, Tensor<T> value)
Parameters
Type | Name | Description |
---|---|---|
String | name | name |
Tensor<T> | value | Tensor |
Returns
Type | Description |
---|---|
NamedOnnxValue |
Type Parameters
Name | Description |
---|---|
T |