Last active
March 14, 2018 12:06
-
-
Save rnrneverdies/62b8c5e12342ceb5c45283b279820625 to your computer and use it in GitHub Desktop.
LoadModelAsync 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 LoadModelAsync() | |
{ | |
try | |
{ | |
// Load Model | |
var modelFile = await StorageFile.GetFileFromApplicationUriAsync( | |
new Uri($"ms-appx:///Assets/FERPlus.onnx")); | |
model = await LearningModelPreview.LoadModelFromStorageFileAsync(modelFile); | |
// Retrieve model input and output variable descriptions (we already know | |
// the model takes an image in and outputs a tensor) | |
var inputFeatures = model.Description.InputFeatures.ToList(); | |
var outputFeatures = model.Description.OutputFeatures.ToList(); | |
inputImageDescriptor = | |
inputFeatures.FirstOrDefault( | |
feature => feature.ModelFeatureKind == LearningModelFeatureKindPreview.Image) | |
as ImageVariableDescriptorPreview; | |
outputTensorDescriptor = | |
outputFeatures.FirstOrDefault( | |
feature => feature.ModelFeatureKind == LearningModelFeatureKindPreview.Tensor) | |
as TensorVariableDescriptorPreview; | |
} | |
catch (Exception) | |
{ | |
model = null; | |
throw; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment