protected override async Task EvaluateAsync(MLModelResult result, VideoFrame inputFrame) { // Initialize the input BirdModelInput input = new BirdModelInput() { data = inputFrame }; // Evaluate the input BirdModelOutput output = await EvaluateAsync(input, result.CorrelationId); // Get first label from output string label = output.classLabel?.FirstOrDefault(); // Find probability for label if (string.IsNullOrEmpty(label) == false) { float probability = output.loss?.ContainsKey(label) == true ? output.loss[label] : 0f; result.OutputFeatures = new MLModelOutputFeature[] { new MLModelOutputFeature() { Label = label, Probability = probability } }; } }
public async Task <BirdModelOutput> EvaluateAsync(BirdModelInput input, string correlationId = "") { BirdModelOutput output = new BirdModelOutput(); // Bind input and output model LearningModelBindingPreview binding = new LearningModelBindingPreview(this.LearningModel); binding.Bind("data", input.data); binding.Bind("classLabel", output.classLabel); binding.Bind("loss", output.loss); // Evaluate the bindings LearningModelEvaluationResultPreview evalResult = await this.LearningModel.EvaluateAsync(binding, correlationId); return(output); }