Skip to content

Instantly share code, notes, and snippets.

@ThiagoLira
Created January 18, 2022 17:24
Show Gist options
  • Save ThiagoLira/b2bdb56182a9f790c78d5a7897d6e250 to your computer and use it in GitHub Desktop.
Save ThiagoLira/b2bdb56182a9f790c78d5a7897d6e250 to your computer and use it in GitHub Desktop.
update function
public int Update(double[] currentState)
{
Tensor<double> input = new DenseTensor<double>(new[] {3});
input[0] = currentState[0];
input[1] = currentState[1];
input[2] = currentState[2];
// Setup inputs and outputs
var inputs = new List<NamedOnnxValue>()
{
// the model has only one input, the state tuple
NamedOnnxValue.CreateFromTensor<double>("0", input)
};
using (var results = session.Run(inputs))
{
Tensor<double> outputs = results.First().AsTensor<double>();
var maxValue = outputs.Max();
var maxIndex = outputs.ToList().IndexOf(maxValue);
return maxIndex;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment