Improve memory handling of grayscale conversion during detetion
All checks were successful
Build Dev PWA / Build-PWA (push) Successful in 37s

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-06-28 11:28:02 -07:00
parent 5448bb000c
commit 8786555df5

View File

@@ -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')