Skip to content

Commit

Permalink
change nn -> classifier, comments about sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman authored and bomanimc committed Nov 4, 2020
1 parent 207c5c2 commit 3418909
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ml5 Example
Image classification using Convolutional Neural Network
This example uses a callback pattern to create the classifier
=== */
let nn;
let classifier;
const IMAGE_WIDTH = 64;
const IMAGE_HEIGHT = 64;
const IMAGE_CHANNELS = 4;
Expand Down Expand Up @@ -40,8 +40,10 @@ function setup() {
};

// construct the neural network
nn = ml5.neuralNetwork(options);
// nn.loadData('daytime_nightime.json', train);
classifier = ml5.neuralNetwork(options);

// An option to load sample data for quick testing
// classifier.loadData('daytime_nightime.json', train);
}

function draw() {
Expand All @@ -50,7 +52,7 @@ function draw() {

function addData() {
console.log('adding data', labelInput.value());
nn.addData({ image: video }, { label: labelInput.value() });
classifier.addData({ image: video }, { label: labelInput.value() });
}

function train() {
Expand All @@ -59,13 +61,13 @@ function train() {
epochs: 4,
};

nn.normalizeData();
nn.train(TRAINING_OPTIONS, finishedTraining);
classifier.normalizeData();
classifier.train(TRAINING_OPTIONS, finishedTraining);
}

function finishedTraining() {
console.log('finished training');
nn.classify([video], gotResults);
classifier.classify([video], gotResults);
}

function gotResults(err, result) {
Expand All @@ -74,5 +76,5 @@ function gotResults(err, result) {
return;
}
resultLabel.html(`${result[0].label}`);
nn.classify([video], gotResults);
classifier.classify([video], gotResults);
}

0 comments on commit 3418909

Please sign in to comment.