This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors examples to match diy-nn-refactor branch (#195)
* neural noteplayer example * example inspired by Eyeo 2019 Rebecca Fiebrink talk * rename musical mouse example * example tweaks and oscillator * adds refactoring examples * updates examples based in refactor * updates xor" * rm unused co2net * updates examples for regression * updates musical note example * adds experimental normalizationOptions * adds example of multi layered network * changes activations * adds simple classification example * changes .normalize() to .normalizeData() * updates all examples to handle array of .predict() or .classify() output
- Loading branch information
Showing
20 changed files
with
487 additions
and
2,490 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
p5js/NeuralNetwork/NeuralNetwork_Simple-Classification/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Neural Network</title> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/p5.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.8.0/addons/p5.dom.min.js"></script> | ||
<script src="http://localhost:8080/ml5.js" type="text/javascript"></script> | ||
</head> | ||
|
||
<body> | ||
<h1>Neural Network Classification</h1> | ||
<label for="avatar">Load Model:</label> | ||
<input type="file" id="load" multiple /> | ||
<script src="sketch.js"></script> | ||
</body> | ||
|
||
</html> |
56 changes: 56 additions & 0 deletions
56
p5js/NeuralNetwork/NeuralNetwork_Simple-Classification/sketch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2018 ml5 | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
/* === | ||
ml5 Example | ||
Image classification using MobileNet and p5.js | ||
This example uses a callback pattern to create the classifier | ||
=== */ | ||
let nn; | ||
|
||
const options = { | ||
inputs: 1, | ||
outputs: 2, | ||
task: 'classification', | ||
debug: true | ||
} | ||
|
||
function setup(){ | ||
createCanvas(400, 400); | ||
nn = ml5.neuralNetwork(options); | ||
|
||
|
||
console.log(nn) | ||
createTrainingData(); | ||
nn.normalizeData(); | ||
|
||
const trainingOptions={ | ||
batchSize: 24, | ||
epochs: 32 | ||
} | ||
|
||
nn.train(trainingOptions,finishedTraining); // if you want to change the training options | ||
// nn.train(finishedTraining); // use the default training options | ||
} | ||
|
||
function finishedTraining(){ | ||
|
||
nn.classify([300], function(err, result){ | ||
console.log(result); | ||
}) | ||
|
||
} | ||
|
||
function createTrainingData(){ | ||
for(let i = 0; i < 400; i++){ | ||
if(i%2 === 0){ | ||
const x = random(0, width/2); | ||
nn.addData( [x], ['left']) | ||
} else { | ||
const x = random(width/2, width); | ||
nn.addData( [x], ['right']) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.