示例#1
0
        public async Task <CNTKGraphModelOutput> EvaluateAsync(CNTKGraphModelInput input)
        {
            CNTKGraphModelOutput        output  = new CNTKGraphModelOutput();
            LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel);

            binding.Bind("Input338", input.Input338);
            binding.Bind("Plus692_Output_0", output.Plus692_Output_0);
            LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty);

            return(output);
        }
示例#2
0
        private async void btnLoadPicture_ClickAsync(object sender, RoutedEventArgs e)
        {
            lstEmotions.Items.Clear();
            var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".png");

            var file = await filePicker.PickSingleFileAsync();

            if (file == null)
            {
                //operation cancelled
                return;
            }

            BitmapImage imgBitmap = new BitmapImage(new Uri(file.Path));

            imgPicture.Source = imgBitmap;

            StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/Emotion.onnx"));

            CNTKGraphModel model = await CNTKGraphModel.CreateCNTKGraphModel(modelFile);

            SoftwareBitmap softwareBitmap;

            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                VideoFrame          vf    = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap);
                CNTKGraphModelInput input = new CNTKGraphModelInput();
                input.Input338 = vf;

                CNTKGraphModelOutput output = await model.EvaluateAsync(input);

                foreach (var item in output.Plus692_Output_0)
                {
                    lstEmotions.Items.Add(item.ToString());
                }
            }
        }