Created
January 8, 2019 22:22
-
-
Save zsajjad/3f1bf808b17e571808b9b02be3f9b253 to your computer and use it in GitHub Desktop.
Running ONNX.js model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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