private async Task EvaluteImageAsync(VideoFrame videoFrame) { try { var startTime = DateTime.Now; if (model == null) { var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/Inceptionv3.onnx")); if (modelFile != null) { model = new Inceptionv3Model(); await MLHelper.CreateModelAsync(modelFile, model); } } var input = new Inceptionv3Input() { image = ImageFeatureValue.CreateFromVideoFrame(videoFrame) }; var res = await model.EvaluateAsync(input) as Inceptionv3Output; if (res != null) { var results = new List <LabelResult>(); if (res.classLabelProbs != null) { var dict = res.classLabelProbs.FirstOrDefault(); foreach (var kv in dict) { results.Add(new LabelResult { Label = kv.Key, Result = (float)Math.Round(kv.Value * 100, 2) }); } results.Sort((p1, p2) => { return(p2.Result.CompareTo(p1.Result)); }); } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { previewControl.EvalutionTime = (DateTime.Now - startTime).TotalSeconds.ToString(); outputText.Text = res.classLabel.GetAsVectorView().FirstOrDefault(); resultList.ItemsSource = results; }); } } catch (Exception ex) { await AlertHelper.ShowMessageAsync(ex.ToString()); } }
/// <summary> /// evaluate a model /// </summary> /// <param name="input"></param> /// <param name="learningModel"></param> /// <returns></returns> public async static Task <IMachineLearningOutput> EvaluateAsync(IMachineLearningInput input, IMachineLearningModel learningModel) { var output = await learningModel.EvaluateAsync(input); return(output); }