Esempio n. 1
0
        private async void RecogNumberFromInk()
        {
            // 从文件加载模型
            var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/mnist.onnx"));

            var model = await mnistModel.CreateFromStreamAsync(modelFile);

            // 组织输入
            var inputArray = await GetInputDataFromInk();

            var inputTensor = TensorFloat.CreateFromArray(new List <long> {
                784
            }, inputArray);
            var modelInput = new mnistInput {
                port = inputTensor
            };

            // 推理
            var result = await model.EvaluateAsync(modelInput);

            // 得到每个数字的得分
            var scoreList = result.dense3port.GetAsVectorView().ToList();

            // 从输出中取出得分最高的
            var max = scoreList.IndexOf(scoreList.Max());

            // 显示在控件中
            lbResult.Text = max.ToString();
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }