-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathml_example.js
More file actions
17 lines (17 loc) · 827 Bytes
/
Copy pathml_example.js
File metadata and controls
17 lines (17 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function PreviewImage() {
document.getElementById("loading-gif").style.display = 'inline';
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function(oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
const image = document.getElementById('uploadPreview');
const result = document.getElementById('result');
const probability = document.getElementById('probability');
const classifier = ml5.imageClassifier('Mobilenet');
classifier.predict(image, function(results) {
result.innerText = results[0].className;
probability.innerText = results[0].probability.toFixed(2) * 100;
document.getElementById("loading-gif").style.display = 'none';
});
};