Ejemplo n.º 1
0
        public async Task <Squeezenet_oldModelOutput> EvaluateAsync(Squeezenet_oldModelInput input)
        {
            Squeezenet_oldModelOutput   output  = new Squeezenet_oldModelOutput();
            LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);

            binding.Bind("data_0", input.data_0);
            binding.Bind("softmaxout_1", output.softmaxout_1);
            LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty);

            return(output);
        }
Ejemplo n.º 2
0
        protected override async Task EvaluateAsync(MLModelResult result, VideoFrame inputFrame)
        {
            // Initialize the input
            Squeezenet_oldModelInput input = new Squeezenet_oldModelInput()
            {
                data = inputFrame
            };

            // Evaluate the input
            Squeezenet_oldModelOutput output = await EvaluateAsync(input, result.CorrelationId);

            // Get first label from output
            List <float> resultProbabilities = output.softmaxout_1 as List <float>;

            // Find the result of the evaluation in the bound output (the top classes detected with the max confidence)
            List <float> topProbabilities = new List <float>()
            {
                0.0f, 0.0f, 0.0f
            };
            List <int> topProbabilityLabelIndexes = new List <int>()
            {
                0, 0, 0
            };

            for (int i = 0; i < resultProbabilities.Count; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (resultProbabilities[i] > topProbabilities[j])
                    {
                        topProbabilityLabelIndexes[j] = i;
                        topProbabilities[j]           = resultProbabilities[i];
                        break;
                    }
                }
            }



            float probability = topProbabilities[0];

            string label = ListOfObjectLabels[topProbabilityLabelIndexes[0]];

            result.OutputFeatures = new MLModelOutputFeature[]
            {
                new MLModelOutputFeature()
                {
                    Label = label, Probability = probability
                }
            };
        }