-
Notifications
You must be signed in to change notification settings - Fork 2
/
training.js
54 lines (43 loc) · 1.09 KB
/
training.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
let leaves = {
lobed:[],
entire:[],
}
let size = 200;
let index;
function preload(){
for (counter = 0; counter < size; counter++){
index = nf(counter + 1, 3, 0);
leaves.lobed.push(loadImage(`dataset/data/lobed_${index}.png`));
// console.log(`data/lobed_${index}.png`);
index = nf(counter + size + 1, 3, 0);
leaves.entire.push(loadImage(`dataset/data/entire_${index}.png`));
// console.log(`data/entire_${index}.png`);
}
}
function setup(){
let options = {
inputs: [70, 70, 4],
task: "imageClassification",
debug: "true",
}
shapeClassifier = ml5.neuralNetwork(options);
for (label in leaves){
for (item in leaves[label]){
let image = leaves[label][item];
shapeClassifier.addData( {image: image}, {label: label} );
}
}
shapeClassifier.normalizeData();
}
function keyPressed() {
if (keyCode === 84) { // "t"
startTraining();
}
}
function startTraining(){
shapeClassifier.train({ epochs: 50 }, finishedTraining);
}
function finishedTraining() {
console.log(">>> TRAINING FINISHED <<<")
shapeClassifier.save();
}