-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (27 loc) · 918 Bytes
/
index.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
let net;
const inputButton = document.getElementById("imageFile");
const fileButton = document.getElementById("imageButton");
const imgLocation = document.getElementById("imgUpload");
fileButton.addEventListener("click",function() {
inputButton.click();
});
function loadImage(event){
imgLocation.src = URL.createObjectURL(event.target.files[0]);
}
async function classifyImage(){
console.log("Classify in progress...");
const result = await net.classify(imgLocation);
console.log("Classification completed");
document.getElementById('result').innerText = `
Prediction: \n${result[0].className}\n
Probability: \n${result[0].probability}\n
`
}
async function app() {
// load the model
console.log('Loading mobilenet...');
net = await mobilenet.load();
console.log('Sucessfully loaded model');
document.getElementById('classify').addEventListener("click", classifyImage);
}
app();