From 8786555df5d5af2fd893b3e1c22536b2bba85b1e Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Fri, 28 Jun 2024 11:28:02 -0700 Subject: [PATCH] Improve memory handling of grayscale conversion during detetion Signed-off-by: Justin Georgi --- src/pages/detection-mixin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/detection-mixin.js b/src/pages/detection-mixin.js index 21b2c02..aad01eb 100644 --- a/src/pages/detection-mixin.js +++ b/src/pages/detection-mixin.js @@ -27,10 +27,12 @@ export default { async localDetect(imageData) { console.time('pre-process') const [modelWidth, modelHeight] = model.inputs[0].shape.slice(1, 3) + let gTense = null const input = tf.tidy(() => { - var gTense = tf.image.rgbToGrayscale(tf.image.resizeBilinear(tf.browser.fromPixels(imageData), [modelWidth, modelHeight])).div(255.0).expandDims(0) + gTense = tf.image.rgbToGrayscale(tf.image.resizeBilinear(tf.browser.fromPixels(imageData), [modelWidth, modelHeight])).div(255.0).expandDims(0) return tf.concat([gTense,gTense,gTense],3) }) + tf.dispose(gTense) console.timeEnd('pre-process') console.time('run prediction')