public async Task <sthv2_tpnOutput> EvaluateAsync(sthv2_tpnInput input) { binding.Bind("input", input.input); var result = await session.EvaluateAsync(binding, "0"); var output = new sthv2_tpnOutput(); output.output = result.Outputs["output"] as TensorFloat; return(output); }
private async void CurrentVideoFrame(ThreadPoolTimer timer) { //複数スレッドでの同時実行を抑制 if (!semaphore.Wait(0)) { return; } try { // カメラから256x256の画像を取得 VideoFrame previewFrame = new VideoFrame(BitmapPixelFormat.Bgra8, 256, 256); await this.mediaCapture.GetPreviewFrameAsync(previewFrame); if (frameBuffer.Count >= target_length) { frameBuffer.RemoveAt(0); // 先頭をpop } frameBuffer.Add(previewFrame); // 末尾に追加 frame_refresh_count += 1; if (ModelGen != null && previewFrame != null && frame_refresh_count == target_length) { frame_refresh_count = 0; ModelInput.input = CustomTensorize(frameBuffer, mean, std, true); // Evaluate the model ModelOutput = await ModelGen.EvaluateAsync(ModelInput); // Convert output to datatype var outtensor = ModelOutput.output; IReadOnlyList <float> logits = outtensor.GetAsVectorView(); var exp_logits = logits.Select(l => Math.Exp(l)); var exp_logits_sum = exp_logits.Sum(); var probs = exp_logits.Select(el => el / exp_logits_sum); ////IReadOnlyList<float> vectorImage = ModelOutput.Plus214_Output_0.GetAsVectorView(); var prob_list = probs.ToList(); // Query to check for highest probability digit var sorted_logt = prob_list.OrderBy(elm => - 1 * elm).ToList(); // Display the results on UI Thread. var ignored = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { int topk = 5; string result = ""; for (int k = 0; k < topk; k++) { var prob = sorted_logt[k]; string label = labelList[prob_list.IndexOf(prob)]; result = result + "\n" + "Prob: " + prob.ToString("0.00") + ", Label: " + label; } //予測結果を表示 this.msgTbk.Text = result; }); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { semaphore.Release(); } }