Example #1
0
        public static async Task <CNTKGraphModel> CreateCNTKGraphModel(StorageFile file)
        {
            LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file);

            CNTKGraphModel model = new CNTKGraphModel();

            model.learningModel = learningModel;
            return(model);
        }
Example #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());
                }
            }
        }