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); }
private async void recognizeButton_Click(object sender, RoutedEventArgs e) { FileOpenPicker fileOpenPicker = new FileOpenPicker(); fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.FileTypeFilter.Add(".jpg"); fileOpenPicker.FileTypeFilter.Add(".bmp"); fileOpenPicker.FileTypeFilter.Add(".png"); fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; var inputFile = await fileOpenPicker.PickSingleFileAsync(); if (inputFile == null) { // The user cancelled the picking operation return; } imageLabel.Text = "Recognizing..."; SoftwareBitmap softwareBitmap; using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read)) { // Create the decoder from the stream BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); // Get the SoftwareBitmap representation of the file softwareBitmap = await decoder.GetSoftwareBitmapAsync(); softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore); var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(softwareBitmap); previewImage.Source = source; VideoFrame vf = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); await CropImageAsync(vf); 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]; } } imageLabel.Text = string.Format("{0}\r\n({1})", classList.classList[maxIndex], maxProb); } }