TensorFloat TensorFloat TensorFloat TensorFloat TensorFloat Class

Definition

A 32-bit float tensor object.

public : sealed class TensorFloat : ILearningModelFeatureValue, ITensor
struct winrt::Windows::AI::MachineLearning::TensorFloat : ILearningModelFeatureValue, ITensor
public sealed class TensorFloat : ILearningModelFeatureValue, ITensor
Public NotInheritable Class TensorFloat Implements ILearningModelFeatureValue, ITensor
// This class does not provide a public constructor.
Attributes

Windows 10 requirements

Device family
Windows 10, version 1809 (introduced v10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduced v1)

Examples

The following example creates a session and a binding, binds the input image, and then binds the output to a created TensorFloat:

void BindModel(
	LearningModel model, 
	LearningModelDeviceKind deviceKind, 
	hstring inputName, 
	hstring outputName, 
	VideoFrame imageFrame)
{
	// Create a session and binding
	LearningModelSession session = LearningModelSession{ model, LearningModelDevice(deviceKind) };
	LearningModelBinding binding = LearningModelBinding{ session };

	// Bind the input image
	binding.Bind(inputName, ImageFeatureValue::CreateFromVideoFrame(imageFrame));

	// Bind the output
	vector<int64_t> shape({ 1, 1000, 1, 1 });
	binding.Bind(outputName, TensorFloat::Create(shape));
}

Remarks

A tensor is a multi-dimensional array of values. A float tensor is a tensor of 32-bit floating point values.

The layout of tensors is row-major, with tightly packed contiguous data representing each dimension. The total size of a tensor is the product of the size of each dimension.

Windows Server

To use this API on Windows Server, you must use Windows Server 2019 with Desktop Experience.

Thread safety

This API is thread-safe.

Version history

Windows version SDK version Value added
1903 18362 CreateFromBuffer
1903 18362 CreateFromShapeArrayAndDataArray

Properties

Kind Kind Kind Kind Kind
Shape Shape Shape Shape Shape

Returns the count and size of each dimension.

TensorKind TensorKind TensorKind TensorKind TensorKind

Returns the data type of the tensor.

Methods

Close() Close() Close() Close() Close()
Create() Create() Create() Create() Create()

Creates a 32-bit float tensor object without allocating a buffer.

Create(IIterable<Int64>) Create(IIterable<Int64>) Create(IIterable<Int64>) Create(IIterable<Int64>) Create(IIterable<Int64>)

Creates a 32-bit float tensor object and allocates a buffer of size shape.

CreateFromArray(IIterable<Int64>, Single[]) CreateFromArray(IIterable<Int64>, Single[]) CreateFromArray(IIterable<Int64>, Single[]) CreateFromArray(IIterable<Int64>, Single[]) CreateFromArray(IIterable<Int64>, Single[])

Creates a 32-bit float tensor object, allocates a buffer of size shape, and copies all of data into it.

CreateFromBuffer(Int64[], IBuffer) CreateFromBuffer(Int64[], IBuffer) CreateFromBuffer(Int64[], IBuffer) CreateFromBuffer(Int64[], IBuffer) CreateFromBuffer(Int64[], IBuffer)

Creates a float tensor object with the given shape and uses the underlying buffer in data for subsequent evaluation.

CreateFromIterable(IIterable<Int64>, IIterable<Single>) CreateFromIterable(IIterable<Int64>, IIterable<Single>) CreateFromIterable(IIterable<Int64>, IIterable<Single>) CreateFromIterable(IIterable<Int64>, IIterable<Single>) CreateFromIterable(IIterable<Int64>, IIterable<Single>)

Creates a 32-bit float tensor object, allocates a buffer of size shape, and copies all of data into it.

CreateFromShapeArrayAndDataArray(Int64[], Single[]) CreateFromShapeArrayAndDataArray(Int64[], Single[]) CreateFromShapeArrayAndDataArray(Int64[], Single[]) CreateFromShapeArrayAndDataArray(Int64[], Single[]) CreateFromShapeArrayAndDataArray(Int64[], Single[])

Creates a 32-bit float tensor object, allocates a buffer of size shape, and copies all of data into it.

CreateReference() CreateReference() CreateReference() CreateReference() CreateReference()

Returns an IMemoryBufferReference representation of the buffer backing the 32-bit float tensor object.

GetAsVectorView() GetAsVectorView() GetAsVectorView() GetAsVectorView() GetAsVectorView()

Returns a read-only view of the data.

See also