コード例 #1
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);
        }
コード例 #2
0
        private async void TestBtn_Click(object sender, RoutedEventArgs e)
        {
            // Trigger file picker to select an image file
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            fileOpenPicker.FileTypeFilter.Add(".png");
            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            StorageFile selectedStorageFile = await fileOpenPicker.PickSingleFileAsync();

            SoftwareBitmap softwareBitmap;

            using (IRandomAccessStream stream = await selectedStorageFile.OpenAsync(FileAccessMode.Read))
            {
                // Create the decoder from the stream
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                // Get the SoftwareBitmap representation of the file in BGRA8 format
                softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
            }

            // Display the image
            //SoftwareBitmapSource imageSource = new SoftwareBitmapSource();
            //await imageSource.SetBitmapAsync(softwareBitmap);
            //UIPreviewImage.Source = imageSource;

            // Encapsulate the image within a VideoFrame to be bound and evaluated
            VideoFrame inputImage = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap);

            ModelInput.input_placeholer00 = ImageFeatureValue.CreateFromVideoFrame(inputImage);
            //Evaluate the model
            ModelOutput = await ModelGen.EvaluateAsync(ModelInput);

            //Convert output to datatype
            IReadOnlyList <float> vectorImage = ModelOutput.stage_30mid_conv70BiasAdd00.GetAsVectorView();
            IList <float>         imageList   = vectorImage.ToList();

            //LINQ query to check for highest probability digit
            var maxIndex = imageList.IndexOf(imageList.Max());

            //Display the results
            Result.Text = maxIndex.ToString();
        }