Commit 3d95104e authored by Mohammad Hussain's avatar Mohammad Hussain

Initial commit

parents
Pipeline #4937 failed with stages
in 4 seconds
File added
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/addons/p5.sound.min.js"></script>
<script src="./lib/ml5.min.js"></script>
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
{"modelTopology":{"class_name":"Sequential","config":[{"class_name":"Dense","config":{"units":16,"activation":"relu","use_bias":true,"kernel_initializer":{"class_name":"VarianceScaling","config":{"scale":1,"mode":"fan_avg","distribution":"normal","seed":null}},"bias_initializer":{"class_name":"Zeros","config":{}},"kernel_regularizer":null,"bias_regularizer":null,"activity_regularizer":null,"kernel_constraint":null,"bias_constraint":null,"name":"dense_Dense1","trainable":true,"batch_input_shape":[null,34],"dtype":"float32"}},{"class_name":"Dense","config":{"units":3,"activation":"sigmoid","use_bias":true,"kernel_initializer":{"class_name":"VarianceScaling","config":{"scale":1,"mode":"fan_avg","distribution":"normal","seed":null}},"bias_initializer":{"class_name":"Zeros","config":{}},"kernel_regularizer":null,"bias_regularizer":null,"activity_regularizer":null,"kernel_constraint":null,"bias_constraint":null,"name":"dense_Dense2","trainable":true}}],"keras_version":"tfjs-layers 1.2.2","backend":"tensor_flow.js"},"weightsManifest":[{"paths":["./model.weights.bin"],"weights":[{"name":"dense_Dense1/kernel","shape":[34,16],"dtype":"float32"},{"name":"dense_Dense1/bias","shape":[16],"dtype":"float32"},{"name":"dense_Dense2/kernel","shape":[16,3],"dtype":"float32"},{"name":"dense_Dense2/bias","shape":[3],"dtype":"float32"}]}]}
\ No newline at end of file
{"inputUnits":[34],"outputUnits":3,"inputs":{"0":{"dtype":"number","min":252.1592114543357,"max":437.5736068517376},"1":{"dtype":"number","min":134.4571208396153,"max":266.1748803568165},"2":{"dtype":"number","min":246.57892952188413,"max":446.3140458670276},"3":{"dtype":"number","min":126.63680703086925,"max":263.3534324006495},"4":{"dtype":"number","min":243.96148473431026,"max":427.2495696605065},"5":{"dtype":"number","min":125.41031032510202,"max":271.97149741486965},"6":{"dtype":"number","min":251.55904847976058,"max":460.5951305486073},"7":{"dtype":"number","min":136.26151815492506,"max":252.3319290488319},"8":{"dtype":"number","min":244.31419208965337,"max":411.58919782434054},"9":{"dtype":"number","min":135.9697942008749,"max":279.0317395974321},"10":{"dtype":"number","min":306.4347158212643,"max":488.74483997129323},"11":{"dtype":"number","min":175.74857120625455,"max":268.36960522984435},"12":{"dtype":"number","min":291.2185906899138,"max":384.096887599655},"13":{"dtype":"number","min":180.2787267673782,"max":299.07425177724735},"14":{"dtype":"number","min":338.0928933364838,"max":524.3457459566886},"15":{"dtype":"number","min":134.8812919750548,"max":354.70959787945066},"16":{"dtype":"number","min":226.08819020886634,"max":396.46170989811765},"17":{"dtype":"number","min":120.5743075067769,"max":373.4648527922453},"18":{"dtype":"number","min":326.65347569634804,"max":590.9265446058723},"19":{"dtype":"number","min":67.05784431442646,"max":429.6974107768335},"20":{"dtype":"number","min":156.0418998614157,"max":456.9413665117111},"21":{"dtype":"number","min":30.402044404087476,"max":454.1062382926717},"22":{"dtype":"number","min":304.2129534448099,"max":448.42752259609523},"23":{"dtype":"number","min":255.1618148476524,"max":403.7248482806408},"24":{"dtype":"number","min":255.1957122624269,"max":401.75151088781524},"25":{"dtype":"number","min":284.21814708449455,"max":397.712142825359},"26":{"dtype":"number","min":292.9359004743847,"max":435.18376757526954},"27":{"dtype":"number","min":341.7815933078818,"max":513.696038021214},"28":{"dtype":"number","min":244.31741487677797,"max":389.0041917945906},"29":{"dtype":"number","min":363.75966211508586,"max":517.630242316114},"30":{"dtype":"number","min":245.35800331517268,"max":433.8055187916895},"31":{"dtype":"number","min":389.7893597043281,"max":557.8279726500632},"32":{"dtype":"number","min":219.46274914471957,"max":399.41514338666235},"33":{"dtype":"number","min":448.6052746986552,"max":558.1644362734074}},"outputs":{"0":{"dtype":"number","min":106,"max":255},"1":{"dtype":"number","min":0,"max":159},"2":{"dtype":"number","min":0,"max":255}},"isNormalized":true}
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "image-demo",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
const express = require("express");
const app = express();
const port = 3000;
app.use(express.static("./"));
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
// ml5.js: Pose Classification
// The Coding Train / Daniel Shiffman
// https://thecodingtrain.com/learning/ml5/7.2-pose-classification.html
// https://youtu.be/FYgYyq-xqAw
// All code: https://editor.p5js.org/codingtrain/sketches/JoZl-QRPK
// Separated into three sketches
// 1: Data Collection: https://editor.p5js.org/codingtrain/sketches/kTM0Gm-1q
// 2: Model Training: https://editor.p5js.org/codingtrain/sketches/-Ywq20rM9
// 3: Model Deployment: https://editor.p5js.org/codingtrain/sketches/c5sDNr8eM
let video;
let poseNet;
let pose;
let skeleton;
let brain;
let rSlider, gSlider, bSlider;
function setup() {
createCanvas(640, 480);
// Colour sliders
rSlider = createSlider(0, 255, 0);
gSlider = createSlider(0, 255, 0);
bSlider = createSlider(0, 255, 0);
// Load video
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelLoaded);
poseNet.on('pose', gotPoses);
let options = {
inputs: 34,
outputs: 3,
task: 'regression',
debug: true
};
brain = ml5.neuralNetwork(options);
// Load models
const modelInfo = {
model: 'model/model.json',
metadata: 'model/model_meta.json',
weights: 'model/model.weights.bin'
};
brain.load(modelInfo, brainLoaded);
}
function brainLoaded() {
console.log('pose ready!');
predictColor();
}
// Will predict colours when posing
function predictColor() {
if (pose) {
let inputs = [];
for (let i = 0; i < pose.keypoints.length; i++) {
let x = pose.keypoints[i].position.x;
let y = pose.keypoints[i].position.y;
inputs.push(x);
inputs.push(y);
}
brain.predict(inputs, gotResult);
} else {
setTimeout(predictColor, 100);
}
}
function gotResult(error, results) {
console.log(results);
let r = results[0].value;
let g = results[1].value;
let b = results[2].value;
rSlider.value(r);
gSlider.value(g);
bSlider.value(b);
predictColor();
}
function gotPoses(poses) {
// console.log(poses);
if (poses.length > 0) {
pose = poses[0].pose;
skeleton = poses[0].skeleton;
}
}
function modelLoaded() {
console.log('poseNet ready');
}
function draw() {
push();
translate(video.width, 0);
scale(-1, 1);
image(video, 0, 0, video.width, video.height);
if (pose) {
for (let i = 0; i < skeleton.length; i++) {
let a = skeleton[i][0];
let b = skeleton[i][1];
strokeWeight(1);
stroke(5);
// Nose
fill(255,0,0);
ellipse(pose.nose.x, pose.nose.y, 40);
// Left eye
fill(255);
ellipse(pose.leftEye.x, pose.leftEye.y, 50);
fill(0,255,255);
ellipse(pose.leftEye.x, pose.leftEye.y, 25);
// Right eye
fill(255);
ellipse(pose.rightEye.x, pose.rightEye.y, 50);
fill(0,255,255);
ellipse(pose.rightEye.x, pose.rightEye.y, 25);
fill(255);
line(a.position.x, a.position.y, b.position.x, b.position.y);
}
// Pose points during movement
for (let i = 0; i < pose.keypoints.length; i++) {
let x = pose.keypoints[i].position.x;
let y = pose.keypoints[i].position.y;
fill(0);
stroke(255);
ellipse(x, y, 13, 13);
}
}
pop();
let r = rSlider.value();
let g = gSlider.value();
let b = bSlider.value();
background(r, g, b, 100);
}
html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment