-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (50 loc) · 1.68 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {EarModel, GeneralUtils} from './ear.js';
console.log("ENTERED")
var canvas = document.getElementById("canvas")
var ctx = canvas.getContext("2d");
var img = document.getElementById("img");
var status = document.getElementById("status");
async function main(){
let im0s = tf.browser.fromPixels(img)
await tf.browser.toPixels(im0s, canvas);
let em = new EarModel()
status.innerText = "Loading model"
await em.loadModel()
async function doInference(doPost){
tf.engine().startScope()
let prediction = await em.pred(/*canvas, ctx, */img, doPost);
tf.engine().endScope()
return prediction
}
status.innerText = "Starting initial inference"
let pred = await doInference()
// console.log(fpscheck + " FPS")
status.innerText = "Image is drawn to canvas!"
pred.forEach(det => {
GeneralUtils.drawToCanvas(det, ctx)
})
let btn = document.createElement("BUTTON")
btn.innerText = "FPS Checker"
btn.onclick = async () => {
let fpsAmt = 0
let length = 50;
status.innerText = "Running FPS Test(Without postprocessing)..."
for(let i = 0; i<length; i++){
const START = window.performance.now()
await doInference(false)
const END = window.performance.now()
fpsAmt += END-START
}
fpsAmt /= length
console.log(1/fpsAmt * 1000)
status.innerText = `FPS is ${Math.round(1/fpsAmt * 1000)} FPS`
}
document.getElementById("btncontainer").appendChild(btn)
}
// img.onload = async () => {
// console.log("image loaded")
// await main()
// }
window.onload = async () => {
await main()
}