예제 #1
0
        async void OnFrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args)
        {
            if (Interlocked.CompareExchange(ref this.processingFlag, 1, 0) == 0)
            {
                try
                {
                    using (var frame = sender.TryAcquireLatestFrame())
                        using (var videoFrame = frame.VideoMediaFrame?.GetVideoFrame())
                        {
                            if (videoFrame != null)
                            {
                                // If there is a frame, set it as input to the model
                                ONNXModelInput input = new ONNXModelInput();
                                input.data = videoFrame;
                                // Evaluate the input data
                                var evalOutput = await model.EvaluateAsync(input);

                                // Do something with the model output
                                await this.ProcessOutputAsync(evalOutput);
                            }
                        }
                }
                finally
                {
                    Interlocked.Exchange(ref this.processingFlag, 0);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Evaluate the model
        /// </summary>
        /// <param name="input">The VideoFrame to evaluate</param>
        /// <returns></returns>
        public async Task <ONNXModelOutput> EvaluateAsync(ONNXModelInput input)
        {
            var output  = new ONNXModelOutput();
            var binding = new LearningModelBinding(_session);

            binding.Bind("data", input.data);
            binding.Bind("classLabel", output.classLabel);
            binding.Bind("loss", output.loss);
            LearningModelEvaluationResult result = await _session.EvaluateAsync(binding, "0");

            return(output);
        }