-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
34 lines (31 loc) · 872 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 mobilenet;
let img;
img.crossOrigin='Anonymous';
function modelready(){
console.log('Model is ready!');
mobilenet.predict(img,gotresults)
}
function gotresults(error,results){
if(error){console.error(error);}
else{
console.log(results);
let label=results[0].label;
let prob=results[0].confidence.toFixed(3);
fill(0);
textSize(64);
text(`This is a ${label}`,10,50);
text(`With ${prob*100}% confidence`,10,height-30);
createP(`Label: ${label}`);
createP(`Probability: ${prob}`);
console.log('Done');
}
}
function imageready(){image(img,0,0,width,height);}
function setup(){
createCanvas(640,480);
let imgname='img/sloth.jpg'
img=createImg(imgname,imageready);
img.hide();
background(0);
mobilenet=ml5.imageClassifier('MobileNet',modelready);
}