Add safari-based logic for detection calls

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2024-08-15 15:36:38 -07:00
parent bb0b7273f9
commit df1f0f2213
4 changed files with 48 additions and 29 deletions

View File

@@ -57,7 +57,7 @@ async function loadModel(weights, preload) {
}
async function localDetect(imageData) {
console.time('pre-process')
console.time('sw: pre-process')
const [modelWidth, modelHeight] = model.inputs[0].shape.slice(1, 3)
let gTense = null
const input = tf.tidy(() => {
@@ -65,15 +65,15 @@ async function localDetect(imageData) {
return tf.concat([gTense,gTense,gTense],3)
})
tf.dispose(gTense)
console.timeEnd('pre-process')
console.timeEnd('sw: pre-process')
console.time('run prediction')
console.time('sw: run prediction')
const res = model.predict(input)
const tRes = tf.transpose(res,[0,2,1])
const rawRes = tRes.arraySync()[0]
console.timeEnd('run prediction')
console.timeEnd('sw: run prediction')
console.time('post-process')
console.time('sw: post-process')
const outputSize = res.shape[1]
let rawBoxes = []
let rawScores = []
@@ -138,14 +138,14 @@ async function localDetect(imageData) {
}
tf.dispose(res)
tf.dispose(input)
console.timeEnd('post-process')
console.timeEnd('sw: post-process')
return output || { detections: [] }
}
async function videoFrame (vidData) {
const [modelWidth, modelHeight] = model.inputs[0].shape.slice(1, 3)
console.time('frame-process')
console.time('sw: frame-process')
let rawCoords = []
try {
const input = tf.tidy(() => {
@@ -171,6 +171,6 @@ async function videoFrame (vidData) {
} catch (e) {
console.log(e)
}
console.timeEnd('frame-process')
console.timeEnd('sw: frame-process')
return {cds: rawCoords, mW: modelWidth, mH: modelHeight}
}