Dela via


ImageFeatureValue Class

Definition

Describes the properties of the image used to pass into a model.

public ref class ImageFeatureValue sealed : ILearningModelFeatureValue
/// [Windows.Foundation.Metadata.ContractVersion(Windows.AI.MachineLearning.MachineLearningContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ImageFeatureValue final : ILearningModelFeatureValue
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.AI.MachineLearning.MachineLearningContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ImageFeatureValue : ILearningModelFeatureValue
Public NotInheritable Class ImageFeatureValue
Implements ILearningModelFeatureValue
Inheritance
Object Platform::Object IInspectable ImageFeatureValue
Attributes
Implements

Windows requirements

Device family
Windows 10, version 1809 (introduced in 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (introduced in v1.0)

Examples

The following example creates a LearningModelSession and a LearningModelBinding, binds the input to an ImageFeatureValue created from a VideoFrame, and then binds the output.

#include <winrt/Windows.AI.MachineLearning.h>
#include <winrt/Windows.Media.h>
using namespace winrt;
using namespace Windows::AI::MachineLearning;
using namespace Windows::Media;

...

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

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

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

Remarks

This is the recommended way of passing images as inputs and outputs. It allows you to focus on the image and not have to worry about either conversions or tensorization. You can create an ImageFeatureValue using the ImageFeatureValue.CreateFromVideoFrame method.

Windows ML supports two types of VideoFrame: SoftwareBitmap and IDirect3DSurface. The system takes care of both conversion and tensorization for the images to match the format the model requires. The currently supported model format types are Gray8, Rgb8, and Bgr8, and the currently supported pixel range is 0-255.

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.

Properties

Kind

Returns the Kind associated with the feature.

VideoFrame

Gets the video frame.

Methods

CreateFromVideoFrame(VideoFrame)

Creates an ImageFeatureValue using the given video frame.

Applies to

See also