public static async Task <ResNet50Model> CreateResNet50Model(StorageFile file) { LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file); ResNet50Model model = new ResNet50Model(); model.learningModel = learningModel; return(model); }
private async Task EvaluteImageAsync(VideoFrame videoFrame) { try { var startTime = DateTime.Now; if (model == null) { var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/Resnet50.onnx")); if (modelFile != null) { model = new ResNet50Model(); await MLHelper.CreateModelAsync(modelFile, model); } } var input = new ResNet50ModelInput() { image = videoFrame }; var res = await model.EvaluateAsync(input) as ResNet50ModelOutput; if (res != null) { var results = new List <LabelResult>(); foreach (var kv in res.classLabelProbs) { results.Add(new LabelResult { Label = kv.Key, Result = (float)Math.Round(kv.Value * 100, 2) }); } results.Sort((p1, p2) => { return(p2.Result.CompareTo(p1.Result)); }); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { previewControl.EvalutionTime = (DateTime.Now - startTime).TotalSeconds.ToString(); outputText.Text = res.classLabel.FirstOrDefault(); resultList.ItemsSource = results; }); } } catch (Exception ex) { await AlertHelper.ShowMessageAsync(ex.ToString()); } }