Пример #1
0
        public async Task <IDictionary <string, float> > EvaluateAsync(SoftwareBitmap bitmap)
        {
            var videoFrame        = VideoFrame.CreateWithSoftwareBitmap(bitmap);
            var imageFeatureValue = ImageFeatureValue.CreateFromVideoFrame(videoFrame);
            var input             = new SmartInkModelInput()
            {
                data = imageFeatureValue
            };
            var output = new SmartInkModelOutput();

            _binding.Bind("data", input.data);

            _binding.Bind("classLabel", output.ClassLabel);

            _binding.Bind("loss", output.Loss);
            LearningModelEvaluationResult result = await _session.EvaluateAsync(_binding, "0");

            output.ClassLabel = result.Outputs["classLabel"] as TensorString;//).GetAsVectorView()[0];

            output.Loss = result.Outputs["loss"] as IList <IDictionary <string, float> >;
            var dict = new Dictionary <string, float>();

            foreach (var key in output.Loss[0].Keys)
            {
                dict.Add(key, output.Loss[0][key]);
            }

            return(dict);
        }
Пример #2
0
        private async Task LoadAndEvaluateModelAsync(VideoFrame _inputFrame, string _modelFileName)
        {
            LearningModelBinding _binding     = null;
            VideoFrame           _outputFrame = null;
            LearningModelSession _session;

            try
            {
                //Load and create the model
                if (_model == null)
                {
                    var modelFile =
                        await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///{_modelFileName}"));

                    _model = await LearningModel.LoadFromStorageFileAsync(modelFile);
                }

                // Create the evaluation session with the model
                _session = new LearningModelSession(_model);

                // Get input and output features of the model
                var inputFeatures  = _model.InputFeatures.ToList();
                var outputFeatures = _model.OutputFeatures.ToList();

                // Create binding and then bind input/ output features
                _binding = new LearningModelBinding(_session);

                _inputImageDescriptor =
                    inputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Tensor) as TensorFeatureDescriptor;

                _outputTensorDescriptor =
                    outputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Tensor) as TensorFeatureDescriptor;

                TensorFloat       outputTensor = TensorFloat.Create(_outputTensorDescriptor.Shape);
                ImageFeatureValue imageTensor  = ImageFeatureValue.CreateFromVideoFrame(_inputFrame);

                // Bind inputs +outputs
                _binding.Bind(_inputImageDescriptor.Name, imageTensor);
                _binding.Bind(_outputTensorDescriptor.Name, outputTensor);


                // Evaluate and get the results
                var results = await _session.EvaluateAsync(_binding, "test");

                Debug.WriteLine("ResultsEvaluated: " + results.ToString());

                var outputTensorList = outputTensor.GetAsVectorView();
                var resultsList      = new List <float>(outputTensorList.Count);
                for (int i = 0; i < outputTensorList.Count; i++)
                {
                    resultsList.Add(outputTensorList[i]);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"error: {ex.Message}");
                _model = null;
            }
        }
Пример #3
0
 public async Task<ShuffleNetOutput> EvaluateAsync(ShuffleNetInput input)
 {
     binding.Bind("gpu_0/data_0", input.gpu_00data_0);
     var result = await session.EvaluateAsync(binding, "0");
     var output = new ShuffleNetOutput();
     output.gpu_00softmax_1 = result.Outputs["gpu_0/softmax_1"] as TensorFloat;
     return output;
 }
        public async Task <MultiObjectDetectionModelv8Output> EvaluateAsync(MultiObjectDetectionModelv8Input input)
        {
            var output = new MultiObjectDetectionModelv8Output();

            if (input != null)
            {
                binding.Bind("image", input.Image);
                var result = await session.EvaluateAsync(binding, "0");

                output.Grid = result.Outputs["grid"] as TensorFloat;
            }
            else
            {
                throw new NullReferenceException();
            }
            return(output);
        }
Пример #5
0
        public async Task <TensorFloat> EvaluateAsync(TensorFloat input)
        {
            binding.Bind(inName, input);
            binding.Bind(outName, TensorFloat.Create(new long[] { 1, 1, InHeight, OutHeight }));
            var result = await session.EvaluateAsync(binding, inName);

            return(result.Outputs[outName] as TensorFloat);
        }
Пример #6
0
        public async Task <AlexNetOutput> EvaluateAsync(AlexNetInput input)
        {
            binding.Bind("data_0", input.data_0);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new AlexNetOutput();

            output.prob_1 = result.Outputs["prob_1"] as TensorFloat;
            return(output);
        }
        public async Task <ImageClassifierOutput> EvaluateAsync(ImageClassifierInput input)
        {
            binding.Bind("modelInput", input.modelInput);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new ImageClassifierOutput();

            output.modelOutput = result.Outputs["modelOutput"] as TensorFloat;
            return(output);
        }
Пример #8
0
        public async Task <HandwriteOutput> EvaluateAsync(HandwriteInput input)
        {
            binding.Bind("Input3", input.Input3);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new HandwriteOutput();

            output.Plus214_Output_0 = result.Outputs["Plus214_Output_0"] as TensorFloat;
            return(output);
        }
Пример #9
0
        public async Task <mnistOutput> EvaluateAsync(mnistInput input)
        {
            binding.Bind("fc1x", input.fc1x);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new mnistOutput();

            output.activation3y = result.Outputs["activation3y"] as TensorFloat;
            return(output);
        }
Пример #10
0
        public async Task <mnistOutput> EvaluateAsync(mnistInput input)
        {
            binding.Bind("port", input.port);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new mnistOutput();

            output.dense3port = result.Outputs["dense3port"] as TensorFloat;
            return(output);
        }
        public async Task <FER_Emotion_RecognitionOutput> EvaluateAsync(FER_Emotion_RecognitionInput input)
        {
            binding.Bind("Input3", input.Input3);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new FER_Emotion_RecognitionOutput();

            output.Plus692_Output_0 = result.Outputs["Plus692_Output_0"] as TensorFloat;
            return(output);
        }
Пример #12
0
        public async Task <emotion_ferplusOutput> EvaluateAsync(emotion_ferplusInput input)
        {
            binding.Bind("Input338", input.Input338);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new emotion_ferplusOutput();

            output.Plus692_Output_0 = result.Outputs["Plus692_Output_0"] as TensorFloat;
            return(output);
        }
Пример #13
0
        public async Task <IList <PredictionModel> > PredictImageAsync(VideoFrame image)
        {
            var imageFeature = ImageFeatureValue.CreateFromVideoFrame(image);
            var bindings     = new LearningModelBinding(this.Session);

            bindings.Bind("data", imageFeature);
            var result = await Session.EvaluateAsync(bindings, "");

            return(Postprocess(result.Outputs["model_outputs0"] as TensorFloat));
        }
Пример #14
0
        public async Task <rain_princessOutput> EvaluateAsync(rain_princessInput input)
        {
            binding.Bind("input1", input.input1);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new rain_princessOutput();

            output.output1 = result.Outputs["output1"] as TensorFloat;
            return(output);
        }
Пример #15
0
        public async Task <Output> EvaluateAsync(Input input)
        {
            binding.Bind("data", input.data);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new Output();

            output.mobilenetv20_output_flatten0_reshape0 = result.Outputs["mobilenetv20_output_flatten0_reshape0"] as TensorFloat;
            return(output);
        }
Пример #16
0
        public async Task <Output> EvaluateAsync(Input input)
        {
            binding.Bind("image", input.image);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new Output();

            output.grid = result.Outputs["grid"] as TensorFloat;
            return(output);
        }
Пример #17
0
        public async Task <modelOutput> EvaluateAsync(modelInput input)
        {
            binding.Bind("data_0", input.data_0);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new modelOutput();

            output.softmaxout_1 = result.Outputs["softmaxout_1"] as TensorFloat;
            return(output);
        }
Пример #18
0
        public async Task <model1Output> EvaluateAsync(model1Input input)
        {
            binding.Bind("dense_1_input", input.dense_1_input);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new model1Output();

            output.activation_10Softmax00 = result.Outputs["activation_1/Softmax:0"] as TensorFloat;
            return(output);
        }
Пример #19
0
        public async Task <mnistOutput> EvaluateAsync(mnistInput input)
        {
            binding.Bind("input_placeholer:0", input.input_placeholer00);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new mnistOutput();

            output.stage_30mid_conv70BiasAdd00 = result.Outputs["stage_3/mid_conv7/BiasAdd:0"] as TensorFloat;
            return(output);
        }
Пример #20
0
        public async Task <resnet100Output> EvaluateAsync(resnet100Input input)
        {
            binding.Bind("data", input.data);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new resnet100Output();

            output.fc1 = result.Outputs["fc1"] as TensorFloat;
            return(output);
        }
        public async Task <pointilismOutput> EvaluateAsync(pointilismInput input)
        {
            binding.Bind("input1", input.input1);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new pointilismOutput();

            output.output1 = result.Outputs["output1"] as TensorFloat;
            return(output);
        }
Пример #22
0
        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);
        }
Пример #23
0
        public async Task <BedroomOutput> EvaluateAsync(BedroomInput input)
        {
            binding.Bind("img_placeholder:0", input.img_placeholder00);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new BedroomOutput();

            output.add_3700 = result.Outputs["add_3700"] as TensorFloat;
            return(output);
        }
        public async Task <sthv2_tpnOutput> EvaluateAsync(sthv2_tpnInput input)
        {
            binding.Bind("input", input.input);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new sthv2_tpnOutput();

            output.output = result.Outputs["output"] as TensorFloat;
            return(output);
        }
Пример #25
0
        public async Task <modelOutput> EvaluateAsync(modelInput input)
        {
            binding.Bind("Input3", input.Input3);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new modelOutput();

            output.Plus692_Output_0 = result.Outputs["Plus692_Output_0"] as TensorFloat;
            return(output);
        }
        public async Task <Inceptionv3_convertedOutput> EvaluateAsync(Inceptionv3_convertedInput input)
        {
            binding.Bind("input_1_0", input.input_1_0);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new Inceptionv3_convertedOutput();

            output.dense_2_Softmax_01 = result.Outputs["dense_2_Softmax_01"] as TensorFloat;
            return(output);
        }
Пример #27
0
        public async Task <hangulOutput> EvaluateAsync(hangulInput input)
        {
            binding.Bind("input:0", input.input00);
            binding.Bind("keep_prob:0", input.keep_prob);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new hangulOutput();

            output.output00 = result.Outputs["output:0"] as TensorFloat;
            return(output);
        }
Пример #28
0
        public async Task <Output> EvaluateAsync(Input input)
        {
            binding.Bind("data", input.data);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new Output();

            output.classLabel = result.Outputs["classLabel"] as TensorString;
            output.loss       = result.Outputs["loss"] as IList <Dictionary <string, float> >;
            return(output);
        }
Пример #29
0
        public async Task <SentimentPolarityOutput> EvaluateAsync(SentimentPolarityInput input)
        {
            binding.Bind("input", input.input);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new SentimentPolarityOutput();

            output.classLabel       = result.Outputs["classLabel"] as TensorString;
            output.classProbability = result.Outputs["classProbability"] as IList <Dictionary <string, float> >;
            return(output);
        }
Пример #30
0
        public async Task <MyCustomVisionModelOutput> EvaluateAsync(MyCustomVisionModelInput input)
        {
            binding.Bind("data", input.Data);
            var result = await session.EvaluateAsync(binding, "0");

            var output = new MyCustomVisionModelOutput();

            output.ClassLabel = result.Outputs["classLabel"] as TensorString;
            output.Loss       = result.Outputs["loss"] as IList <IDictionary <string, float> >;
            return(output);
        }