Пример #1
0
        private async Task EvaluateVideoFrameAsync(VideoFrame inputFrame)
        {
            if (inputFrame != null)
            {
                try
                {
                    // Get ONNX file
                    string modelPath
                        = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "FruitDetection.onnx");
                    var modelFile = await StorageFile.GetFileFromPathAsync(modelPath);

                    // Create WinML Model
                    var model        = new FruitDetectionModel();
                    var learninModel = await model.CreateFruitDetectionModel(modelFile);

                    // Set image(VideoFrame)
                    var input = new FruitDetectionModelInput
                    {
                        data = inputFrame
                    };

                    // Detect image
                    var output = await learninModel.EvaluateAsync(input);

                    ResultText.Text       = output.classLabel[0];
                    ResultText.Visibility = Visibility.Visible;
                }
                catch (Exception ex)
                {
                }
            }
        }
        public async Task <FruitDetectionModelOutput> EvaluateAsync(FruitDetectionModelInput input)
        {
            FruitDetectionModelOutput   output  = new FruitDetectionModelOutput();
            LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);

            binding.Bind("data", input.data);
            binding.Bind("classLabel", output.classLabel);
            binding.Bind("loss", output.loss);
            LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty);

            return(output);
        }