Skip to content

Instantly share code, notes, and snippets.

@zsajjad
Created January 8, 2019 22:22
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 zsajjad/3f1bf808b17e571808b9b02be3f9b253 to your computer and use it in GitHub Desktop.
Save zsajjad/3f1bf808b17e571808b9b02be3f9b253 to your computer and use it in GitHub Desktop.
Running ONNX.js model
export async function runModel(model: InferenceSession, preProcessedData: Tensor): Promise<[Tensor, number]> {
const start = new Date();
try {
const outputData = await model.run([preProcessedData]);
const end = new Date();
const inferenceTime = (end.getTime() - start.getTime());
const output = outputData.values().next().value;
return [output, inferenceTime];
} catch (e) {
console.error(e);
throw new Error();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment