Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0355d38
added_instantiation_files
mop9047 Apr 1, 2025
b8f031e
solved convergence issue with compile()
mop9047 Apr 5, 2025
bf67b69
instantiation code form TSDATA
mop9047 Apr 5, 2025
1228a59
added previous examples and refactored layers
mop9047 May 7, 2025
bedb655
added helper functions, simplified examples
mop9047 May 8, 2025
61c7d27
changes based on PR comments
mop9047 May 24, 2025
494ce16
convert linear/spatial to flag
mop9047 May 24, 2025
576d54c
Code Clean up and Simplified examples
mop9047 Jun 4, 2025
60d0eb4
Merged timeseries-as-task to timeseries-base and bug fixes
mop9047 Jun 4, 2025
1356185
merged timeseries as task to timeseries-base and bug fixes
mop9047 Jun 4, 2025
c5f78cf
Transferred files into NeuralNetwork Folder and code cleanup
mop9047 Jun 5, 2025
b9a1959
Fixed comment formatting
mop9047 Jun 30, 2025
a6afd6d
Changed Class names to Sequential
mop9047 Jul 1, 2025
174b1d8
changes based on PR comments
mop9047 Jul 10, 2025
3fc035a
chore: changed gestures to gesture
mop9047 Jul 10, 2025
e70ab0e
chore: replace Conv to withCNN
mop9047 Jul 10, 2025
8caffd3
Tweaks to neuralNetwork-sequence-weather-prediction example
gohai Jul 15, 2025
03d3a18
Fix typo
gohai Jul 15, 2025
790a162
Open-code sliding window in example
gohai Jul 17, 2025
f702700
Tweak variable placement and add comment
gohai Jul 17, 2025
4c9594e
fix: sliding window bug
mop9047 Jul 22, 2025
e3d95f2
chore: slidingwindow to verb and rename samplewindow outputs
mop9047 Jul 22, 2025
002213a
chore: change padCoordinate name to setFixedLength
mop9047 Jul 22, 2025
b0c968c
fix: tslayers naming bug
mop9047 Jul 22, 2025
b5adac3
chore: clarify error when task is unknown
mop9047 Jul 22, 2025
c083beb
Rework the neuralNetwork-sequence-mouse-gesture-rdp example
gohai Jul 23, 2025
ec08ad9
Construct NN inside setup() in weather-prediction example
gohai Jul 23, 2025
e8f6958
Shave off two unneeded lines
gohai Jul 23, 2025
f580e64
fix: error capitalization from seqUtils
mop9047 Jul 24, 2025
0998b5b
chore: remove rdp visualizer
mop9047 Jul 24, 2025
0febf59
Rework the neuralNetwork-sequence-hand-gesture example
gohai Jul 26, 2025
17a1cc2
Fix grammar in comment
gohai Jul 26, 2025
21d3054
Use canvasDiv everywhere
gohai Jul 26, 2025
155fde6
Use training/predicting in examples
gohai Jul 26, 2025
9e53b97
Whitespace change
gohai Jul 26, 2025
d4a26a4
Flip for order
gohai Jul 26, 2025
0e71849
Rework neuralNetwork-sequence-hand-gesture-load-model example
gohai Jul 27, 2025
452ed2d
Tweaks to language
gohai Jul 27, 2025
46924ba
Rename targetLength to sequenceLength and other tweaks
gohai Jul 27, 2025
1308865
Revert part of last commit
gohai Jul 27, 2025
024d91f
Rename "predicting" to "classifiying" in classification tasks
gohai Jul 27, 2025
43b9198
feat: filter input/output by labels
mop9047 Jul 28, 2025
0d50690
chore: add new pre-trained models
mop9047 Jul 30, 2025
a7f8eea
chore: trainOptions, mm, barHeight
mop9047 Jul 31, 2025
8fd81c2
chore: friendlier error messages
mop9047 Jul 31, 2025
e84709f
fix: friendly error message normalize
mop9047 Jul 31, 2025
7776f28
chore: error for different lengths
mop9047 Jul 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/timeSeries-hand-gestures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
👋 Hello! This is an ml5.js example made and shared with ❤️.
Learn more about the ml5.js project: https://ml5js.org/
ml5.js license and Code of Conduct: https://github.com/ml5js/ml5-next-gen/blob/main/LICENSE.md

This example demonstrates training a Sign Language classifier through ml5.TimeSeries.
-->

<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ml5.js Time Series Hand Gesture Train and Save</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.4/p5.min.js"></script>
<script src="../../dist/ml5.js"></script>
</head>

<body>
<script src="sketch.js"></script>
</body>
</html>
192 changes: 192 additions & 0 deletions examples/timeSeries-hand-gestures/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* 👋 Hello! This is an ml5.js example made and shared with ❤️.
* Learn more about the ml5.js project: https://ml5js.org/
* ml5.js license and Code of Conduct: https://github.com/ml5js/ml5-next-gen/blob/main/LICENSE.md
*
* This example demonstrates training a Hand Gesture classifier through ml5.TimeSeries.
*/

let seqLength = 50;

let handPose;
let video;

let hands = [];
let sequence = [];

let recordingFinished = false;
let predictedWord = "";

// UI variables
let trainingWords = {};

function preload() {
// Load the handPose model
handPose = ml5.handPose();

// setup the timeseries neural network
let options = {
outputs: ["label"],
task: "classification",
spatialData: "true",
debug: "true",
learningRate: 0.001, // the default learning rate of 0.01 didn't converge for this usecase, thus a learning rate of 0.001 is used (make smaller steps of parameters each update)
};
model = ml5.timeSeries(options);
}

function setup() {
createCanvas(640, 480);

// setup video capture
video = createCapture(VIDEO);
video.size(640, 480);
video.hide();

// place UI elements
UI();

// use handpose model on video
handPose.detectStart(video, gotHands);
}

function draw() {
// draw video on frame
image(video, 0, 0, width, height);

drawPredictedWord();

// if hands are found then start recording
if (hands.length > 0 && recordingFinished == false) {
if (sequence.length <= seqLength) {
// get coordinates from hands (21 points)
handpoints = drawPoints();
sequence.push(handpoints);

// once sequence reaches the seqLength, add sequence as just one X value
} else if (sequence.length > 0) {
// get the training word from the input box
let trainWord = nameField.value();

// if there is a word currently in the box then add data with that label
if (trainWord.length > 0) {
// add data to the model
let target = { label: trainWord };
model.addData(sequence, target);
trainingWordsUpdate();

// if there is no word in the box then classify instead
} else {
// classify the data
model.classify(sequence, gotResults);
}

// reset the sequence
sequence = [];
recordingFinished = true;
}

// can only record again when hand is out of frame
} else {
if (hands.length == 0) {
recordingFinished = false;
}
}
}

function drawPoints() {
let handpoints = [];
// iterate through both hands
for (let i = 0; i < hands.length; i++) {
let hand = hands[i];
for (let j = 0; j < hand.keypoints.length; j++) {
// access the keypoints in the hand
let keypoint = hand.keypoints[j];
handpoints.push(keypoint.x, keypoint.y);

fill(0, 255, 0);
noStroke();
circle(keypoint.x, keypoint.y, 5);
}
}
// assign to a different variable before clearing
let output = handpoints;
handpoints = [];

return output;
}

// Callback function for when handPose outputs data
function gotHands(results) {
// save the output to the hands variable
hands = results;
}

function trainModelAndSave() {
model.normalizeData();
let options = {
epochs: 100,
};
model.train(options, whileTraining, finishedTraining);
nameField.value("");
}

function whileTraining(epoch) {
console.log(epoch);
}

function finishedTraining() {
console.log("finished training.");
model.save("model");
}

function gotResults(results) {
predictedWord = results[0].label;
console.log(predictedWord);
text(predictedWord, 200, 200);
}

function UI() {
nameField = createInput("");
nameField.attribute("placeholder", "Type the word to train");
nameField.position(110, 500);
nameField.size(250);

instructionP = createP(
'I want to train: <br><br> 1.) Type any word you want to pair with a gesture, e.g. "HELLO" <br> 2.) Do the gesture associated to the word, make sure to do it until the points disappear. <br> 3.) Move your hand out of the frame and repeat the gesture, do this multiple times <br> 4.) Do the same for other words e.g. "BYE" <br> 5.) Once all data is collected, press Train and Save<br><br> Tip: have at least 5 datasets for each word'
);
instructionP.style("width", "640px");
dataCountsP = createP("-> After the gesture a tally will appear here <-");

train_but = createButton("Train and Save");
train_but.mouseClicked(trainModelAndSave);
train_but.style("font-family", "Georgia");
train_but.style("font-size", "20px");
train_but.position(500, 490);
}

function drawPredictedWord() {
textSize(100);
fill(255);
text(predictedWord, 100, height / 2);
}

function trainingWordsUpdate() {
let tempWord = nameField.value();
console.log(Object.keys(trainingWords));
if (!(tempWord in trainingWords)) {
trainingWords[tempWord] = 1;
} else {
trainingWords[tempWord]++;
}

let counts = "";
let keys = Object.keys(trainingWords);
console.log("keys", keys);

for (let k of keys) {
counts += k + " : " + trainingWords[k] + "<br>";
}

dataCountsP.html(counts);
}
45 changes: 45 additions & 0 deletions examples/timeSeries-load-model-hand-gestures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!--
👋 Hello! This is an ml5.js example made and shared with ❤️.
Learn more about the ml5.js project: https://ml5js.org/
ml5.js license and Code of Conduct: https://github.com/ml5js/ml5-next-gen/blob/main/LICENSE.md

This example demonstrates loading a Sign Language classifier through ml5.TimeSeries.
-->

<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ml5.js Time Series Hand Gesture load model</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.4/p5.min.js"></script>
<script src="../../dist/ml5.js"></script>
</head>

<body>
<script src="sketch.js"></script>
<div id="canvasDiv"></div>
<p>
This example loads a model that is trained with ASL hand gestures for
Hello and Goodbye. <br />
<br />

Instructions: <br />
1.) Use one hand to do a gesture in front of the camera <br />
2.) Wait for the points to disappear or the prediction appears on
screen<br />
3.) To predict again, remove your hands in the frame and do the gesture
again<br /><br />

How to do gestures for Hello and Goodbye in ASL: <br />
Hello:
<a href="https://babysignlanguage.com/dictionary/hello/"
>https://babysignlanguage.com/dictionary/hello/ </a
><br />
Goodbye:
<a href="https://babysignlanguage.com/dictionary/goodbye/"
>https://babysignlanguage.com/dictionary/goodbye/ </a
><br />
</p>
</body>
</html>
Loading