public async Task <BearModelOutput> EvaluateAsync(BearModelInput input) { binding.Bind("data", input.data); var result = await session.EvaluateAsync(binding, "0"); var output = new BearModelOutput(); output.classLabel = result.Outputs["classLabel"] as TensorString; output.loss = result.Outputs["loss"] as IList <Dictionary <string, float> >; return(output); }
private async void RecognizeBear() { // 加载模型 StorageFile modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/BearModel.onnx")); BearModelModel model = await BearModelModel.CreateFromStreamAsync(modelFile); // 构建输入数据 BearModelInput bearModelInput = await GetInputData(); // 推理 BearModelOutput output = await model.EvaluateAsync(bearModelInput); tbBearType.Text = output.classLabel.GetAsVectorView().ToList().FirstOrDefault(); }