forked from Niketkumardheeryan/ML-CaPsule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
30 lines (27 loc) · 959 Bytes
/
demo.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
const img = document.getElementById("img");
const inputFile = document.getElementById("input");
const upload = document.getElementById("upload");
const prediction = document.getElementById("prediction");
inputFile.onchange = function () {
let input = this.files[0];
//Displaying the Uploaded Image
img.src = window.URL.createObjectURL(input);
upload.innerHTML = "Image Uploaded Successfully!";
img.style.border = "auto";
prediction.innerHTML = "Prediction Loading ...";
//Loading model
mobilenet.load().then((model) => {
// Classify the image.
console.log(img);
model.classify(img).then((predictions) => {
console.log("Predictions: ");
prediction.innerHTML =
"This image is predicted to be a " +
predictions[0].className +
" with " +
predictions[0].probability.toFixed(2) * 100 +
" % confidence";
console.log(predictions);
});
});
};