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 では、SoftwareBitmapIDirect3DSurface の 2 種類の VideoFrame がサポートされています。 システムは、モデルに必要な形式に一致するイメージの変換とテンソル化の両方を処理します。 現在サポートされているモデル形式の種類は Gray8、Rgb8、および Bgr8 であり、サポートされているピクセル範囲は 0-255 です。

Windows Server

Windows Server でこの API を使用するには、Windows Server 2019 デスクトップ エクスペリエンスを使用する必要があります。

スレッド セーフ

この API はスレッド セーフです。

プロパティ

Kind

機能に関連付けられている Kind を返します。

VideoFrame

ビデオ フレームを取得します。

メソッド

CreateFromVideoFrame(VideoFrame)

指定されたビデオ フレームを使用して ImageFeatureValue を作成します。

適用対象

こちらもご覧ください