示例#1
0
文件: model.cs 项目: vadimas/events
        public async Task <modelOutput> EvaluateAsync(modelInput input)
        {
            binding.Bind("data", input.data);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new modelOutput();

            output.model_outputs0 = result.Outputs["model_outputs0"] as TensorFloat;
            return(output);
        }
示例#2
0
        private async Task EvaluateVideoFrameAsync(VideoFrame frame)
        {
            if (frame != null)
            {
                try
                {
                    _stopwatch.Restart();
                    //OnnxModelInput inputData = new OnnxModelInput();
                    modelInput inputData = new modelInput();
                    inputData.data = ImageFeatureValue.CreateFromVideoFrame(frame);
                    var output = await _model.EvaluateAsync(inputData);

                    var product = output.model_outputs0.GetAsVectorView()[0];


                    //var loss = output.Loss[0][product];
                    _stopwatch.Stop();
                    var    lossStr = string.Join(",  ", product + " ");
                    string message = $"Evaluation took {_stopwatch.ElapsedMilliseconds}ms to execute, Predictions: {lossStr}.";


                    //var product = output.ClassLabel.GetAsVectorView()[0];
                    //var loss = output.Loss[0][product];
                    //_stopwatch.Stop();
                    //var lossStr = string.Join(",  ", product + " " + (loss * 100.0f).ToString("#0.00") + "%");
                    // string message = $"Evaluation took {_stopwatch.ElapsedMilliseconds}ms to execute, Predictions: {lossStr}.";

                    Debug.WriteLine(message);
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusBlock.Text = message);
                }
                catch (Exception ex)
                {
                    var err_message = $"error: {ex.Message}";
                    Debug.WriteLine(err_message);
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusBlock.Text = err_message);
                }
            }
        }