コード例 #1
0
        private async Task EvaluateVideoFrameAsync(VideoFrame inputFrame)
        {
            if (inputFrame != null)
            {
                try
                {
                    // Get ONNX file
                    var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/CustomVision.onnx"));

                    // Create WinML Model
                    var model = await CustomVisionModel.CreateOnnxModel(modelFile);

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

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

                    ResultText.Text       = output.classLabel.GetAsVectorView()[0];
                    ResultText.Visibility = Visibility.Visible;
                }
                catch (Exception ex)
                {
                }
            }
        }
コード例 #2
0
        public static async Task <CustomVisionModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            CustomVisionModel learningModel = new CustomVisionModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
コード例 #3
0
        public static async Task <CustomVisionModel> CreateOnnxModel(StorageFile file)
        {
            CustomVisionModel learningModel = new CustomVisionModel();

            learningModel.model = await LearningModel.LoadFromStorageFileAsync(file);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }