Share via


ImageFeatureValue Classe

Definizione

Descrive le proprietà dell'immagine usata per passare un modello.

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
Ereditarietà
Object Platform::Object IInspectable ImageFeatureValue
Attributi
Implementazioni

Requisiti Windows

Famiglia di dispositivi
Windows 10, version 1809 (è stato introdotto in 10.0.17763.0)
API contract
Windows.AI.MachineLearning.MachineLearningContract (è stato introdotto in v1.0)

Esempio

Nell'esempio seguente viene creato un oggetto LearningModelSession e learningModelBinding, viene associato l'input a un oggetto ImageFeatureValue creato da un VideoFrame e quindi viene associato l'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));
}

Commenti

Questo è il modo consigliato per passare le immagini come input e output. Consente di concentrarsi sull'immagine e non è necessario preoccuparsi delle conversioni o della tensorizzazione. È possibile creare un oggetto ImageFeatureValue usando il metodo ImageFeatureValue.CreateFromVideoFrame .

Windows ML supporta due tipi di VideoFrame: SoftwareBitmap e IDirect3DSurface. Il sistema si occupa sia della conversione che della tensorizzazione per le immagini in modo che corrispondano al formato richiesto dal modello. I tipi di formato di modello attualmente supportati sono Gray8, Rgb8 e Bgr8 e l'intervallo di pixel attualmente supportato è 0-255.

Windows Server

Per usare questa API in Windows Server, è necessario usare Windows Server 2019 con Esperienza desktop.

Thread safety

Questa API è thread-safe.

Proprietà

Kind

Restituisce il tipo associato alla funzionalità.

VideoFrame

Ottiene il fotogramma video.

Metodi

CreateFromVideoFrame(VideoFrame)

Crea un oggetto ImageFeatureValue usando il fotogramma video specificato.

Si applica a

Vedi anche