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.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 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.normalize(); | ||
|
||
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.output); | ||
}) | ||
|
||
} | ||
|
||
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']) | ||
} | ||
} | ||
} |
387b470
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!! 😻