Add performance tracking to local detection

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-03-05 15:51:28 -07:00
parent 5086a52849
commit b00b5cf492

View File

@@ -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
}