-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
103 lines (77 loc) · 2.67 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
google.charts.load('current', {packages: ['corechart', 'bar']});
//google.charts.setOnLoadCallback(drawStacked);
let net = null;
//let img_ = null;
//let data_ = null;
function drawStacked(result) {
var data_ = Array((result.length + 1));
data_[0] = ['clase','Probabilidad', { role: "style" }];
data_[1] = [result[0].className, result[0].probability, '#90EE90'];
for (iter = 1; iter < result.length; iter++){
data_[(iter + 1)] = [result[iter].className, result[iter].probability, '#6F76C2'];
}
var data = google.visualization.arrayToDataTable(data_);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1,
{ calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation" },
2]);
var options = {
width: 600,
height: 200,
bar: {groupWidth: "95%"},
legend: { position: "none" },
};
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(view, options);
}
function showFiles() {
// An empty img element
let demoImage = document.getElementById('idImage');
// read the file from the user
let file = document.querySelector('input[type=file]').files[0];
const reader = new FileReader();
reader.onload = function (event) {
// Assign to src --->>> <img src="path-to-file">
demoImage.src = reader.result;
}
//console.log(file);
//console.log(demoImage);
//console.log(demoImage.src);
reader.readAsDataURL(file);
//console.log('ejecutando la prediccion');
app();
//console.log('prediccion terminada');
}
async function app(){
console.log('loading mobilenet...');
net = await mobilenet.load();
console.log('Sucessfully loaded model');
await predice();
}
async function predice(){
//console.log(net);
img_ = document.getElementById('idImage');
//console.log(img_);
if (img_.src != ""){
or_width = img_.width;
or_height = img_.height;
img_.width = 224;
img_.height = 224;
const result = await net.classify(img_);
text_ = '';
for(iter = 0; iter < result.length; iter++){
// text_ += '\n predicción:' + result[iter].className + '\n probabilidad:' + result[iter].probability + '\n';
text_ += '\n predicción:' + result[iter].className + '\n';
}
document.getElementById('console').innerText = text_;
console.log(text_);
img_.width = or_width;
img_.height = or_height;
drawStacked(result);
console.log(result);
}
}
app();