-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (33 loc) · 1.07 KB
/
app.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
var webdnn = require('webdnn');
var nj = require('numjs');
var runner = null;
async function predict(num) {
runner = await webdnn.load('model');
let x = runner.inputs[0];
let y = runner.outputs[0];
//generate random normal distribution (z-noise)
let array = nj.random(100);
//conditional
let label = nj.zeros(10);
label.set(num, 1);
init_x = nj.concatenate([array, label]);
x.set(init_x.tolist());
await runner.run();
//draw
var canvas = document.getElementById('output');
webdnn.Image.setImageArrayToCanvas(y.toActual(), 28, 28, document.getElementById('output'), {
dstW: canvas.getAttribute('width'),
dstH: canvas.getAttribute('height'),
scale: [255, 255, 255],
bias: [0, 0, 0],
color: webdnn.Image.Color.GREY,
order: webdnn.Image.Order.CHW
});
}
window.onload = function() {
document.getElementById('button').onclick = function() {
let num = document.getElementById('number').value;
//console.log(num);
predict(num);
}
}