Skip to content

Instantly share code, notes, and snippets.

@rnrneverdies
Last active March 14, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnrneverdies/62b8c5e12342ceb5c45283b279820625 to your computer and use it in GitHub Desktop.
Save rnrneverdies/62b8c5e12342ceb5c45283b279820625 to your computer and use it in GitHub Desktop.
LoadModelAsync method for the Windows Machine Learning, EmotionRecognition sample.
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