Last active
March 14, 2018 12:05
-
-
Save rnrneverdies/8c2ce6eaacabe3ae6922e62f4aea9ead to your computer and use it in GitHub Desktop.
EvaluateAsync method for the Windows Machine Learning, EmotionRecognition sample.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EmotionRecognizer | |
{ | |
// .... | |
public async Task<Results> EvaluateAsync(VideoFrame inputFrame) | |
{ | |
if (model != null) { | |
// Create bindings for the input and output buffer | |
var binding = new LearningModelBindingPreview(model as LearningModelPreview); | |
var outputVariableList = new List<float>(); | |
binding.Bind(inputImageDescriptor.Name, inputFrame); | |
binding.Bind(outputTensorDescriptor.Name, outputVariableList); | |
// Process the frame through the model | |
var results = await model.EvaluateAsync(binding, String.Empty); | |
var resultProbabilities = results.Outputs[outputTensorDescriptor.Name] as List<float>; | |
// return the result | |
return new Results() | |
{ | |
Neutral = resultProbabilities[0], | |
Happiness = resultProbabilities[1], | |
Surprise = resultProbabilities[2], | |
Sadness = resultProbabilities[3], | |
Anger = resultProbabilities[4], | |
Disgust = resultProbabilities[5], | |
Fear = resultProbabilities[6], | |
Contempt = resultProbabilities[7] | |
}; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment