示例#1
0
        public async Task InferenceImage(string _iamgePath)
        {
            StorageFile imageFile = await StorageFile.GetFileFromPathAsync(_iamgePath);

            using (IRandomAccessStream stream = await imageFile.OpenAsync(FileAccessMode.Read))
            {
                // Create the decoder from the stream
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                // Get the SoftwareBitmap representation of the file
                SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                VideoFrame vf = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap);
                await CropInputImageAsync(vf).ConfigureAwait(false);

                ModelInput.data_0 = cropped_vf;
                ModelOutput       = await ModelGen.EvaluateAsync(ModelInput);

                float maxProb  = 0;
                int   maxIndex = 0;
                for (int i = 0; i < ModelOutput.prob_1.Count; i++)
                {
                    if (ModelOutput.prob_1[i] > maxProb)
                    {
                        maxIndex = i;
                        maxProb  = ModelOutput.prob_1[i];
                    }
                }
                Console.WriteLine(string.Format("max {0}:{1}:{2}", maxIndex, classList.classList[maxIndex], maxProb));
            }
        }
示例#2
0
        public async Task <Vgg19ModelOutput> EvaluateAsync(Vgg19ModelInput input)
        {
            Vgg19ModelOutput            output  = new Vgg19ModelOutput();
            LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);

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

            return(output);
        }