-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsketch.js
34 lines (25 loc) · 775 Bytes
/
sketch.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
let classifier;
let labels = ['mobile','tv'];
preLoad();
// Initialize the Image Classifier method with Custom model
function preLoad() {
classifier = ml5.imageClassifier('./my_model/model.json', modelLoaded);
}
function modelLoaded() {
console.log('Model Loaded!');
}
// predict the result after uploaded
function detectImage() {
var reader = new FileReader();
reader.onload = function () {
var output = document.getElementById('output_image');
output.src = reader.result;
classifier.classify(document.getElementById('output_image'), getResult);
}
reader.readAsDataURL(event.target.files[0]);
}
// result callback function
function getResult(err, results) {
alert(JSON.stringify(results));
alert("Predicted is :", labels[results[0].label]);
}