LearningModelSession.EvaluateAsync(LearningModelBinding, String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用系 結中已系結的功能值,以非同步方式評估機器學習模型。
public:
virtual IAsyncOperation<LearningModelEvaluationResult ^> ^ EvaluateAsync(LearningModelBinding ^ bindings, Platform::String ^ correlationId) = EvaluateAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<LearningModelEvaluationResult> EvaluateAsync(LearningModelBinding const& bindings, winrt::hstring const& correlationId);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<LearningModelEvaluationResult> EvaluateAsync(LearningModelBinding bindings, string correlationId);
function evaluateAsync(bindings, correlationId)
Public Function EvaluateAsync (bindings As LearningModelBinding, correlationId As String) As IAsyncOperation(Of LearningModelEvaluationResult)
參數
- bindings
- LearningModelBinding
系結至具名輸入和輸出特徵的值。
- correlationId
-
String
Platform::String
winrt::hstring
選擇性的使用者提供字串,以連接輸出結果。
傳回
來自評估的 LearningModelEvaluationResult 。
- 屬性
範例
下列範例會從模型擷取第一個輸入和輸出功能、建立輸出框架、系結輸入和輸出特徵,以及評估模型。
private async Task EvaluateModelAsync(
VideoFrame _inputFrame,
LearningModelSession _session,
IReadOnlyList<ILearningModelFeatureDescriptor> _inputFeatures,
IReadOnlyList<ILearningModelFeatureDescriptor> _outputFeatures,
LearningModel _model)
{
ImageFeatureDescriptor _inputImageDescription;
TensorFeatureDescriptor _outputImageDescription;
LearningModelBinding _binding = null;
VideoFrame _outputFrame = null;
LearningModelEvaluationResult _results;
try
{
// Retrieve the first input feature which is an image
_inputImageDescription =
_inputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Image)
as ImageFeatureDescriptor;
// Retrieve the first output feature which is a tensor
_outputImageDescription =
_outputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Tensor)
as TensorFeatureDescriptor;
// Create output frame based on expected image width and height
_outputFrame = new VideoFrame(
BitmapPixelFormat.Bgra8,
(int)_inputImageDescription.Width,
(int)_inputImageDescription.Height);
// Create binding and then bind input/output features
_binding = new LearningModelBinding(_session);
_binding.Bind(_inputImageDescription.Name, _inputFrame);
_binding.Bind(_outputImageDescription.Name, _outputFrame);
// Evaluate and get the results
_results = await _session.EvaluateAsync(_binding, "test");
}
catch (Exception ex)
{
StatusBlock.Text = $"error: {ex.Message}";
_model = null;
}
}
備註
Windows Server
若要在 Windows Server 上使用此 API,您必須搭配桌面體驗使用 Windows Server 2019。
執行緒安全
此 API 是安全線程。