-
Notifications
You must be signed in to change notification settings - Fork 60
/
index.html
51 lines (43 loc) · 1.23 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>WONNX</title>
</head>
<body>
<h1>WONNX on the web</h1>
<textarea id="log" style="width: 100%; height: 300px;"></textarea>
<script type="module">
import init, { Session, Input } from "/target/pkg/wonnx.js";
async function fetchBytes(url) {
const reply = await fetch(url);
const blob = await reply.arrayBuffer();
const arr = new Uint8Array(blob);
return arr;
}
function log(txt) {
document.getElementById("log").append(txt);
}
async function run() {
try {
const [modelBytes, initResult] = await Promise.all([fetchBytes("../data/models/single_relu.onnx"), init()])
console.log("Initialized", { modelBytes, initResult, Session});
const session = await Session.fromBytes(modelBytes);
console.log({session});
const input = new Input();
input.insert("x", [13.0, -37.0]);
console.time("inference");
const result = await session.run(input);
console.timeEnd("inference");
console.log({result});
log(JSON.stringify(Object.fromEntries(result), undefined, "\t"));
session.free();
input.free();
}
catch(e) {
console.error(e, e.toString());
}
}
run();
</script>
</body>
</html>