-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
59 lines (51 loc) · 1.78 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
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>TRAINING</title>
<script src="https://unpkg.com/[email protected]/dist/ml5.min.js"></script>
</head>
<body>
<img src="cats/cat.1.jpg" id="test" width="224px" height="224px">
<button onclick='train()'>TRAIN</button>
<script>
const featureExtractor = ml5.featureExtractor("MobileNet", modelLoaded);
const testImg = document.getElementById("test");
function loadJSON(path, success, error) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (success)
success(JSON.parse(xhr.responseText));
}
}
};
xhr.open("GET", path, true);
xhr.send();
}
function addImages(res) {
const keys = Object.keys(res);
keys.map((note) => {
return res[note].map((id) => {
testImg.src = `cats/cat.${id}.jpg`;
return classifier.addImage(testImg, note.toString(10))
})
});
}
function modelLoaded() {
console.log("Model Loaded!");
}
const classifier = featureExtractor.classification();
loadJSON('formatData.json', addImages)
// Retrain the network
function train() {
classifier.train(function (lossValue) {
console.log("Loss is", lossValue);
});
}
</script>
</body>
</html>