-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
68 lines (60 loc) · 1.29 KB
/
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
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
let mobilenet;
let video;
let label = '';
let left;
let right;
let train;
function modelReady() {
console.log('Model is ready!!!');
mobilenet.predict(gotResults);
}
function videoReady() {
console.log('Video is ready!!!');
mobilenet.predict(gotResults);
}
function gotResults(error, result) {
if (error) {
console.error(error);
} else {
label = result;
fill(0);
textSize(64);
text(label, 10, height - 100);
classifier.classify(gotResults);
}
}
function whileTraining(loss) {
if (loss === null) {
console.log('Training Complete');
classifier.classify(gotResults);
} else {
console.log(loss);
}
}
function setup() {
createCanvas(640, 580);
video = createCapture(VIDEO);
video.hide();
background(0);
mobilenet = ml5.featureExtractor('MobileNet', modelReady);
classifier = mobilenet.classification(video, videoReady);
bookButton = createButton('Book');
bookButton.mousePressed(function () {
classifier.addImage('Book');
});
phoneButton = createButton('Phone');
phoneButton.mousePressed(function () {
classifier.addImage('Phone');
});
trainButton = createButton('Train');
trainButton.mousePressed(function () {
classifier.train(whileTraining);
});
}
function draw() {
background(0);
image(video, 0, 0);
// fill(255);
// textSize(32);
// text(label, 10, height - 34);
}