private async void InkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { // Mnist.onnx がまだ読み込まれていない場合は読み込む if (_model == null) { var mnistModelFilePath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Mnist.onnx"); var modelFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(mnistModelFilePath); _model = await MnistModel.CreateFromStreamAsync(modelFile); } // 手書きの内容を画像に変換してモデルで評価する var visual = await Helper.GetHandWrittenImageAsync(inkCanvas); var result = await _model.EvaluateAsync(new MnistInput { Input3 = ImageFeatureValue.CreateFromVideoFrame(visual), }); // 評価結果を解析して認識した数字を表示する var orderedScores = result.Plus214_Output_0.GetAsVectorView() .Select((score, index) => (score, index)) .OrderByDescending(x => x.score); _results.Clear(); foreach (var text in orderedScores.Select(x => $"{x.index}(score: {x.score})")) { _results.Add(text); } }
public static async Task <MnistModel> CreateFromStreamAsync(IRandomAccessStreamReference stream) { MnistModel learningModel = new MnistModel(); learningModel.model = await LearningModel.LoadFromStreamAsync(stream); learningModel.session = new LearningModelSession(learningModel.model); learningModel.binding = new LearningModelBinding(learningModel.session); return(learningModel); }