示例#1
0
        public static async Task <GoogLeNetPlacesModelModel> CreateGoogLeNetPlacesModelModel(StorageFile file)
        {
            LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);

            GoogLeNetPlacesModelModel model = new GoogLeNetPlacesModelModel();

            model.learningModel = learningModel;
            return(model);
        }
示例#2
0
        private async Task EvaluteImageAsync(VideoFrame videoFrame)
        {
            var startTime = DateTime.Now;

            if (model == null)
            {
                var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/GoogLeNetPlaces.onnx"));

                if (modelFile != null)
                {
                    model = new GoogLeNetPlacesModelModel();
                    await MLHelper.CreateModelAsync(modelFile, model);
                }
            }
            var input = new GoogLeNetPlacesModelModelInput()
            {
                sceneImage = videoFrame
            };

            try
            {
                var res = await model.EvaluateAsync(input) as GoogLeNetPlacesModelModelOutput;

                if (res != null)
                {
                    var results = new List <LabelResult>();
                    foreach (var kv in res.sceneLabelProbs)
                    {
                        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, () =>
                    {
                        outputText.Text              = res.sceneLabel.FirstOrDefault();
                        resultList.ItemsSource       = results;
                        previewControl.EvalutionTime = (DateTime.Now - startTime).TotalSeconds.ToString();
                    });
                }
            }
            catch (Exception ex)
            {
                await AlertHelper.ShowMessageAsync(ex.ToString());
            }
        }