private async void CurrentVideoFrame(ThreadPoolTimer timer) { //複数スレッドでの同時実行を抑制 if (!semaphore.Wait(0)) { return; } try { //AIモデルのインプットデータは解像度224x224,BGRA8にする必要がある。 using (VideoFrame previewFrame = new VideoFrame(BitmapPixelFormat.Bgra8, 224, 224)) { await this.mediaCapture.GetPreviewFrameAsync(previewFrame); if (ModelGen != null && previewFrame != null) { ModelInput.image = Windows.AI.MachineLearning.ImageFeatureValue.CreateFromVideoFrame(previewFrame); // Evaluate the model ModelOutput = await ModelGen.EvaluateAsync(ModelInput); // Convert output to datatype var batchIdx = 0; IDictionary <string, float> vectorImage = ModelOutput.classLabelProbs[batchIdx]; var scoreList = vectorImage.Values.ToList(); var labelList = vectorImage.Keys.ToList(); //IReadOnlyList<float> vectorImage = ModelOutput.Plus214_Output_0.GetAsVectorView(); //IList<float> imageList = vectorImage.ToList(); // Query to check for highest probability digit var maxValue = scoreList.Max(); var maxIndex = scoreList.IndexOf(maxValue); var label = labelList[maxIndex]; // Display the results on UI Thread. var ignored = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { string result = ""; //予測結果を表示 result = result + "Class: " + label + ", Prob: " + maxValue; this.msgTbk.Text = result; }); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { semaphore.Release(); } }
public async Task <mobilenetv2Output> EvaluateAsync(mobilenetv2Input input) { binding.Bind("image", input.image); var result = await session.EvaluateAsync(binding, "0"); var output = new mobilenetv2Output(); output.classLabel = result.Outputs["classLabel"] as TensorString; output.classLabelProbs = result.Outputs["classLabelProbs"] as IList <IDictionary <string, float> >; return(output); }