ImageFeatureValue 類別

定義

描述用來傳入模型的影像屬性。

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
繼承
Object Platform::Object IInspectable ImageFeatureValue
屬性
實作

Windows 需求

裝置系列
Windows 10, version 1809 (已於 10.0.17763.0 引進)
API contract
Windows.AI.MachineLearning.MachineLearningContract (已於 v1.0 引進)

範例

下列範例會建立LearningModelSessionLearningModelBinding、將輸入系結至從VideoFrame建立的ImageFeatureValue,然後系結輸出。

#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));
}

備註

這是將影像當做輸入和輸出傳遞的建議方式。 它可讓您專注于影像,而不需要擔心轉換或張量化。 您可以使用ImageFeatureValue.CreateFromVideoFrame方法建立ImageFeatureValue

Windows ML 支援兩種類型的 VideoFrameSoftwareBitmapIDirect3DSurface。 系統會處理影像的轉換和張量,以符合模型所需的格式。 目前支援的模型格式類型為 Gray8、Rgb8 和 Bgr8,目前支援的圖元範圍為 0-255。

Windows Server

若要在 Windows Server 上使用此 API,您必須搭配桌面體驗使用 Windows Server 2019。

執行緒安全

此 API 是安全線程。

屬性

Kind

傳回與功能相關聯的 Kind。

VideoFrame

取得視訊畫面。

方法

CreateFromVideoFrame(VideoFrame)

使用指定的視訊畫面建立 ImageFeatureValue

適用於

另請參閱