コード例 #1
0
        private async Task EvaluteImageAsync(VideoFrame videoFrame)
        {
            try
            {
                var startTime = DateTime.Now;
                if (model == null)
                {
                    var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/Inceptionv3.onnx"));

                    if (modelFile != null)
                    {
                        model = new Inceptionv3Model();
                        await MLHelper.CreateModelAsync(modelFile, model);
                    }
                }

                var input = new Inceptionv3Input()
                {
                    image = ImageFeatureValue.CreateFromVideoFrame(videoFrame)
                };

                var res = await model.EvaluateAsync(input) as Inceptionv3Output;

                if (res != null)
                {
                    var results = new List <LabelResult>();
                    if (res.classLabelProbs != null)
                    {
                        var dict = res.classLabelProbs.FirstOrDefault();
                        foreach (var kv in dict)
                        {
                            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.GetAsVectorView().FirstOrDefault();
                        resultList.ItemsSource = results;
                    });
                }
            }
            catch (Exception ex)
            {
                await AlertHelper.ShowMessageAsync(ex.ToString());
            }
        }
コード例 #2
0
        public async Task <Inceptionv3Output> EvaluateAsync(Inceptionv3Input input)
        {
            binding.Bind("image", input.image);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new Inceptionv3Output();

            output.classLabel      = result.Outputs["classLabel"] as TensorString;
            output.classLabelProbs = result.Outputs["classLabelProbs"] as IList <Dictionary <string, float> >;
            return(output);
        }