From b00b5cf492f6e14a190f1dedfa43dc4240971360 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Tue, 5 Mar 2024 15:51:28 -0700 Subject: [PATCH] Add performance tracking to local detection Signed-off-by: Justin Georgi --- src/pages/local-detect.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/local-detect.js b/src/pages/local-detect.js index dbac842..f9967d7 100644 --- a/src/pages/local-detect.js +++ b/src/pages/local-detect.js @@ -10,13 +10,18 @@ export default { }) }, async localDetect(imageData) { + console.time('pre-process') const [modelWidth, modelHeight] = model.inputs[0].shape.slice(1, 3); - const input = tf.tidy(() => { return tf.image.resizeBilinear(tf.browser.fromPixels(imageData), [modelWidth, modelHeight]).div(255.0).expandDims(0) }) + console.timeEnd('pre-process') + console.time('run prediction') const res = model.predict(input) + console.timeEnd('run prediction') + + console.time('post-process') const detectAttempts = res.shape[2] const outputSize = res.shape[1] const rawRes = tf.transpose(res,[0,2,1]).dataSync() @@ -69,6 +74,7 @@ export default { tf.dispose(res) tf.dispose(tBoxes) + console.timeEnd('post-process') return output }