コード例 #1
0
ファイル: hangul.cs プロジェクト: iljoong/winml
        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);
        }
コード例 #2
0
        private async void PredictHangul(VideoFrame inputimage)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            // convert to bgr8
            SoftwareBitmap bitgray8 = SoftwareBitmap.Convert(inputimage.SoftwareBitmap, BitmapPixelFormat.Gray8);
            var            buff     = new byte[64 * 64];

            bitgray8.CopyToBuffer(buff.AsBuffer());
            var fbuff = new float[4096];

            for (int i = 0; i < 4096; i++)
            {
                fbuff[i] = (float)buff[i] / 255;
            }

            long[] shape = { 1, 4096 };
            charInput.input00 = TensorFloat.CreateFromArray(shape, fbuff);

            var dummy = new float[1];

            long[] dummy_shape = { };
            charInput.keep_prob = TensorFloat.CreateFromArray(dummy_shape, dummy);

            //Evaluate the model
            charOuput = await charModel.EvaluateAsync(charInput);

            //Convert output to datatype
            IReadOnlyList <float> VectorImage = charOuput.output00.GetAsVectorView();
            IList <float>         ImageList   = VectorImage.ToList();

            //Display top results
            var topPred = ImageList.Select((value, index) => new { index, value })
                          .ToDictionary(pair => pair.index, pair => pair.value)
                          .OrderByDescending(key => key.Value)
                          .ToArray();

            string topLabeltxt = "";

            for (int i = 1; i < 6; i++)
            {
                var item = topPred[i];
                Debug.WriteLine($"{item.Key}, {item.Value}, {charLabel[item.Key]}");
                topLabeltxt += $"{charLabel[item.Key]} ";
            }

            numberLabel.Text = charLabel[topPred[0].Key];
            topLabel.Text    = topLabeltxt;

            Debug.WriteLine($"process time = {sw.Elapsed}");
        }