private async Task EvaluateVideoFrameAsync(VideoFrame inputFrame) { if (inputFrame != null) { try { // Get ONNX file var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/CustomVision.onnx")); // Create WinML Model var model = await CustomVisionModel.CreateOnnxModel(modelFile); // Set image(VideoFrame) var input = new CustomVisionInput { data = inputFrame }; // Detect image var output = await model.EvaluateAsync(input); ResultText.Text = output.classLabel.GetAsVectorView()[0]; ResultText.Visibility = Visibility.Visible; } catch (Exception ex) { } } }
public static async Task <CustomVisionModel> CreateFromStreamAsync(IRandomAccessStreamReference stream) { CustomVisionModel learningModel = new CustomVisionModel(); learningModel.model = await LearningModel.LoadFromStreamAsync(stream); learningModel.session = new LearningModelSession(learningModel.model); learningModel.binding = new LearningModelBinding(learningModel.session); return(learningModel); }
public static async Task <CustomVisionModel> CreateOnnxModel(StorageFile file) { CustomVisionModel learningModel = new CustomVisionModel(); learningModel.model = await LearningModel.LoadFromStorageFileAsync(file); learningModel.session = new LearningModelSession(learningModel.model); learningModel.binding = new LearningModelBinding(learningModel.session); return(learningModel); }