Table of Contents

Class NamedOnnxValue

Namespace
Microsoft.ML.OnnxRuntime
Assembly
Microsoft.ML.OnnxRuntime.dll

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.

public class NamedOnnxValue
Inheritance
NamedOnnxValue
Derived
Inherited Members

Constructors

NamedOnnxValue(string, object)

Constructs an instance of NamedOnnxValue and represents a model input to an inference session.

[Obsolete("Use constructors with valueType or static factory methods")]
protected NamedOnnxValue(string name, object value)

Parameters

name string

input/output name

value object

Object that may be a tensor, Dictionary, IList

Properties

Name

Exposes the name of the of the model input/output

public string Name { get; set; }

Property Value

string

name string

Value

Exposes the underlying managed object

public object Value { get; set; }

Property Value

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.

public OnnxValueType ValueType { get; }

Property Value

OnnxValueType

Methods

AsDictionary<K, V>()

Try-get value as an Dictionary<K,V>.

public IDictionary<K, V> AsDictionary<K, V>()

Returns

IDictionary<K, V>

Dictionary object if contained value is a Dictionary. Null otherwise

Type Parameters

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

public IEnumerable<T> AsEnumerable<T>()

Returns

IEnumerable<T>

Enumerable object if contained value is a Enumerable. Null otherwise

Type Parameters

T

Type

AsTensor<T>()

Try-get value as a Tensor<T>.

public Tensor<T> AsTensor<T>()

Returns

Tensor<T>

Tensor object if contained value is a Tensor. Null otherwise

Type Parameters

T

Type

CreateFromMap<K, V>(string, IDictionary<K, V>)

Instantiates NamedOnnxValue that contains IDictionary{K, V}

public static NamedOnnxValue CreateFromMap<K, V>(string name, IDictionary<K, V> value)

Parameters

name string
value IDictionary<K, V>

Returns

NamedOnnxValue

new instance of NamedOnnxValue

Type Parameters

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

public static NamedOnnxValue CreateFromSequence<T>(string name, IEnumerable<T> value)

Parameters

name string
value IEnumerable<T>

Returns

NamedOnnxValue

Type Parameters

T

CreateFromTensor<T>(string, Tensor<T>)

This is a factory method that instantiates NamedOnnxValue and associated name with an instance of a TensorT

public static NamedOnnxValue CreateFromTensor<T>(string name, Tensor<T> value)

Parameters

name string

name

value Tensor<T>

TensorT

Returns

NamedOnnxValue

Type Parameters

T