-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresnetvis.mjs
More file actions
43 lines (37 loc) · 1.23 KB
/
resnetvis.mjs
File metadata and controls
43 lines (37 loc) · 1.23 KB
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
import * as THREE from 'three';
export class Resnetvis {
constructor(world) {
this.loaded = false
console.log("initing resnetvis")
this.insz = [1, 3, 224, 224]
const resnet = new onnx.InferenceSession();
this.resnet = resnet
resnet.loadModel("./models/resnet18-v1-7.onnx").then(async () => {
this.loaded = true
console.log(resnet)
const fls = new Float32Array(this.insz.reduce((a, b) => a * b)).fill(1)
const ot = new onnx.Tensor(fls, 'float32', this.insz)
const outmap = await resnet.run([ot])
console.log(outmap)
const result = outmap.values().next().value
console.log("RESULT")
console.log(result.data)
})
this.stillRunning = false
}
async inferArr(arr) {
const stime = performance.now()
const ot = new onnx.Tensor(arr, 'float32', this.insz)
const outmap = await this.resnet.run([ot])
const result = outmap.values().next().value
console.log(`took ${performance.now() - stime}`)
return result
}
async update() {
if (false && this.loaded && !this.stillRunning) {
this.stillRunning = true
await this.inferArr(new Float32Array(this.insz.reduce((a, b) => a * b)).fill(1))
this.stillRunning = false
}
}
}