-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.html
143 lines (128 loc) · 5.67 KB
/
testing.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>ICS Final Project</title>
<script src="gpu.js/dist/gpu-browser.min.js"> // Libary for fast computation </script>
<script src="LearnAI.js"></script>
<script src="mnist_784_json - 30k.json"></script>
<!--script src="C:\Users\vsarca\Downloads\Neural-Network-Experiments-2e28014ede7ae696cdccba2783a40352200ac14b\Neural-Network-Experiments-2e28014ede7ae696cdccba2783a40352200ac14b\Assets\Data\Mnist\Trained Networks\Mnist Net.json"></script-->
</head>
<body>
<script>
// We will eventually get our digits from here: https://pkgstore.datahub.io/machine-learning/mnist_784/mnist_784_json/data/617bd9fcff01b7d3621d67cef6405d12/mnist_784_json.json
let dataset=[[], []];
for (let i=0; i<30000; i++)
{
// answer
dataset[1].push([0,0,0,0,0,0,0,0,0,0]);
dataset[1][i][data[i].class] = 1;
// image
dataset[0].push([]);
for (let j=1; j<=784; j++)
{
dataset[0][i].push(data[i]["pixel"+j.toString()]/255);
}
}
// For rendering our dataset in the console
function drawImage(imagenumber) {
let image = "";
for (let i=0; i<28; i++)
{
for (let j=0; j<28; j++)
{
let value = dataset[0][imagenumber][28*i + j];
if (value < 0.19)
image += " ";
else if (value < 0.38)
image += ".";
else if (value < 0.57)
image += "-";
else if (value < 0.76)
image += "*";
else if (value < 0.95)
image += "?";
else
image += "#";
}
image += "\n";
}
console.log(image, "Answer is", data[imagenumber].class);
}
let nn, dl;
let input = document.createElement("input");
input.type = "file";
document.body.onload = function () {
let a = document.getElementById("a");
a.onclick = function(e) {
e.preventDefault();
input.click();
};
input.onchange = function(e) {
let reader = new FileReader();
reader.onload = function () {
nn = new NeuralNetwork(1, 1).fromFile(JSON.parse(reader.result)).generateGPU();
dl = new DeepLearner(nn, dataset, { learnrate: 1, batchsize: 100, batchsplit: 0.9, maxIncorrectGuessesToPrint: 1, regularization: 0.0001, momentum: 0.9 });
}
reader.readAsText(input.files[0]);
}
}
function testOnTrainingData()
{
let totalcorrect = 0;
let totalwrong = 0;
for (let i=27000; i<dataset[0].length; i++)
{
let output = nn.runNetwork(dataset[0][i]);
let cost = nn.averageCost(output, dataset[1][i]);
let largest = 0;
for (let j = 1; j < output.length; j++) {
if (output[j] > output[largest])
largest = j;
}
if (dataset[1][i][largest] == 1) totalcorrect++;
else {
totalwrong++;
if (totalwrong > 1500)
{
console.log("", totalwrong, "Network got case", i+1, "wrong, it guessed", largest, "for");
drawImage(i);
}
else
{
console.log(totalwrong);
}
}
}
console.log("Network got", totalcorrect, "correct and", totalwrong, "wrong");
}
nn = new NeuralNetwork(784, 300, 10).randomize().setActivationFunction(ReLU, ReLUDerivative).generateGPU();
dl = new DeepLearner(nn, dataset, { learnrate: 1, batchsize: 100, batchsplit: 0.9, maxIncorrectGuessesToPrint: 1, regularization: 0.0001, momentum: 0.9 });
dl.train(600);
//NeuralNetwork.print();
//nn = new NeuralNetwork(784, 100, 10).randomize().generateGPU();
//nn = new NeuralNetwork(784, 100, 10).fromFile().generateGPU();
//console.log(nn.runNetwork(dataset[0][0]), "is the result for", dataset[0][0]);
//DeepLearner.print();
//dl = new DeepLearner(nn, dataset, { learnrate: 1, batchsize: 100, batchsplit: 0.9, maxIncorrectGuessesToPrint: 1, regularization: 0.0001, momentum: 0.9 });
//dl.debug = true;
//console.log("Network gets", dl.countAll(), "/ 1000 test cases correct");
//let trainer = dl.train(600);
//setTimeout(function () { clearInterval(trainer); dl.test(); }, 900000);
//let p;
//document.body.onload = function () { p = document.getElementById("p"); }
/*let tester = setInterval(function () {
p.innerHTML = dl.test();
console.log(p.innerHTML);
}, 60000);*/
//let tester = setInterval(function () { console.log("Network gets", dl.countAll(), "/ 1000 test cases correct"); }, 10000);
//let printer = setInterval(function () { console.log("Weights:", nn.layerweights, ", Biases:", nn.layerbiases); }, 10000);
//dl.trainOnce();
//dl.trainOnce();
//dl.trainOnce();
</script>
<p id="p">This is our ICS final project!</p>
<a id="a" style="color: black;" href="#">Click to upload a neural network</a>
</body>
</html>