-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (46 loc) · 1.31 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
let net;
async function app() {
// Init
$('.image-section').hide();
$('.loader').hide();
$('#result').hide();
// Image Selection Preview
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById('imagePreview').src = e.target.result;
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageSelection").change(function () {
$('.image-section').show();
$('#btn-predict').show();
$('#result').text('');
$('#result').hide();
readURL(this);
});
// Load the model
console.log('Loading mobilenet..');
$('.loader').show();
net = await mobilenet.load();
console.log('Successfully loaded model');
$('.loader').hide();
// Prediction
$('#btn-predict').click(async function () {
$(this).hide();
$('.loader').show();
// Perform inference
const imageElement = document.getElementById('imagePreview');
const prediction = await net.classify(imageElement, 1);
// Show results
$('.loader').hide();
console.log(prediction);
$('#result').text(" Predicted class: " + prediction[0]['className'] + "\nProbability: " + prediction[0]['probability']);
$('#result').show();
});
}
app();