-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix imageClassifier webgpu bug + add teachable machine image example (#…
…141) * change to async read * add example sketch * ImageClassifier: Tweaks to example formatting No functional changes * flip video --------- Co-authored-by: Gottfried Haider <[email protected]>
- Loading branch information
1 parent
cd2231c
commit d4d87bc
Showing
3 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
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,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 detecting objects in a live video through ml5.imageClassifier + Teachable Machine. | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<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 imageClassifier + Teachable Machine Example</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.9.2/p5.min.js"></script> | ||
<script src="../../dist/ml5.js"></script> | ||
</head> | ||
<body> | ||
<script src="sketch.js"></script> | ||
</body> | ||
</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,50 @@ | ||
/* | ||
* 👋 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 detecting objects in a live video through ml5.imageClassifier + Teachable Machine. | ||
*/ | ||
|
||
// A variable to initialize the Image Classifier | ||
let classifier; | ||
|
||
// A variable to hold the video we want to classify | ||
let video; | ||
|
||
// Variable for displaying the results on the canvas | ||
let label = "Model loading..."; | ||
|
||
let imageModelURL = "https://teachablemachine.withgoogle.com/models/bXy2kDNi/"; | ||
|
||
function preload() { | ||
classifier = ml5.imageClassifier(imageModelURL + "model.json"); | ||
} | ||
|
||
function setup() { | ||
createCanvas(640, 480); | ||
|
||
// Create the webcam video and hide it | ||
video = createCapture(VIDEO, { flipped: true }); | ||
video.size(width, height); | ||
video.hide(); | ||
|
||
// Start detecting objects in the video | ||
classifier.classifyStart(video, gotResult); | ||
} | ||
|
||
function draw() { | ||
// Each video frame is painted on the canvas | ||
image(video, 0, 0); | ||
|
||
// Printing class with the highest probability on the canvas | ||
fill(0, 255, 0); | ||
textSize(32); | ||
text(label, 20, 50); | ||
} | ||
|
||
// A function to run when we get the results | ||
function gotResult(results) { | ||
// update label variable which is displayed on the canvas | ||
label = results[0].label; | ||
} |
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