-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignRecogniser.mjs
47 lines (35 loc) · 1.36 KB
/
signRecogniser.mjs
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
import { NeuralNetwork } from "./NeuralNetwork";
import { VisualiserServer } from "./visualiser/server";
import { default as mnist } from 'mnist' ;
import { Sigmoid, Tanh, Relu } from './Activators';
const Network = new NeuralNetwork(768, 16, 10, 0.3, Sigmoid);
const inputData = [];
const expectedOutput = [];
var mnistData = mnist.set(8000, 1000);
debugger;
mnistData.training.forEach(training => {
inputData.push(training.input);
expectedOutput.push(training.output);
});
Network.train(inputData, expectedOutput, 10).then(() => {
console.log('done');
});
console.log('Testing with', mnistData.test.length,' number');
setInterval(() => {
let errorCount = 0;
mnistData.test.forEach((test, idx) => {
const answer = Network.ask(test.input);
//console.log(answer.answer, test.output);
const isGoodAnswer = answer.answer.map(Math.round).every((element, index) => element == test.output[index]);
if (!isGoodAnswer) {
errorCount++;
}
});
process.stdout.clearLine();
process.stdout.cursorTo(10);
process.stdout.write(`Total error: ${errorCount} from ${mnistData.test.length}. Error rate: ${errorCount / mnistData.test.length * 100}`);
},5000);
const visualiserServer = new VisualiserServer(Network);
visualiserServer.responseFormatter = (question, answer) => {
return JSON.stringify(answer);
};