Skip to content

Instantly share code, notes, and snippets.

@asus4
Last active February 26, 2020 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asus4/4da31a3c682e8c99914afb5fb81dcc0c to your computer and use it in GitHub Desktop.
Save asus4/4da31a3c682e8c99914afb5fb81dcc0c to your computer and use it in GitHub Desktop.
// the image 28 * 28 grayscale
float[,] inputs = new float[28, 28];
// the array of probability
float[] outputs = new float[10];
void Start()
{
// Read bytes from model and make Interpreter
interpreter = new Interpreter(File.ReadAllBytes(path));
// Allocate input buffer
interpreter.ResizeInputTensor(0, new int[] { 1, 28, 28, 1 });
interpreter.AllocateTensors();
}
void Update()
{
// Set input data
interpreter.SetInputTensorData(0, inputs);
// Blackbox!!
interpreter.Invoke();
// Get data
interpreter.GetOutputTensorData(0, outputs);
}
void OnDestroy()
{
interpreter?.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment