private async Task EvaluateVideoFrameAsync(VideoFrame frame) { if (frame != null) { try { MyCustomVisionModelInput inputData = new MyCustomVisionModelInput { data = frame }; var results = await _model.EvaluateAsync(inputData); var loss = results.loss.ToList().OrderByDescending(x => x.Value); var lossStr = string.Join(", ", loss.Select(l => l.Key + " " + (l.Value * 100.0f).ToString("#0.00") + "%")); var message = $" Predictions: {lossStr}"; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusText.Text = message); Debug.WriteLine(message); List <string> linesToDisplay = loss.Take(4).Select(a => $"{a.Key} {(a.Value * 100.0f):#0.00}%").ToList(); _spiDisplay.WriteLinesToScreen(linesToDisplay); } catch (Exception ex) { Debug.WriteLine($"error: {ex.Message}"); } } }
public async Task <MyCustomVisionModelOutput> EvaluateAsync(MyCustomVisionModelInput input) { MyCustomVisionModelOutput output = new MyCustomVisionModelOutput(); LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel); binding.Bind("data", input.data); binding.Bind("classLabel", output.classLabel); binding.Bind("loss", output.loss); LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty); return(output); }