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
Revising Teachable Machine Snippets #218
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
p5js/ImageClassification/ImageClassification_Teachable-Machine/model/metadata.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
p5js/ImageClassification/ImageClassification_Teachable-Machine/model/model.json
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-2.05 MB
p5js/ImageClassification/ImageClassification_Teachable-Machine/model/weights.bin
Binary file not shown.
51 changes: 0 additions & 51 deletions
51
p5js/ImageClassification/ImageClassification_Teachable-Machine/sketch.js
This file was deleted.
Oops, something went wrong.
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>Webcam Image Classification using a pre-trained customized model and p5.js</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script> | ||
<script src="http://localhost:8080/ml5.js" type="text/javascript"></script> | ||
</head> | ||
|
||
<body> | ||
<h1>Teachable Machine</h1> | ||
<p>This is a demonstration of image classification using a model trained with Google's Teachable | ||
Machine project. If you cover the camera, this model will classify the image as "nighttime," otherwise will classify | ||
anything else as "daytime." </p> | ||
<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,68 @@ | ||
// Copyright (c) 2019 ml5 | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
/* === | ||
ml5 Example | ||
Webcam Image Classification using a pre-trained customized model and p5.js | ||
This example uses p5 preload function to create the classifier | ||
=== */ | ||
|
||
// Classifier Variable | ||
let classifier; | ||
// Model URL | ||
let imageModelURL = 'https://storage.googleapis.com/teachable-machine-pubilshed-models/fa542ec0-b94b-4aa9-add4-c256963b0720/model.json'; | ||
|
||
// Video | ||
let video; | ||
|
||
// To store the classification | ||
let label = ""; | ||
|
||
// Load the model first | ||
function preload() { | ||
classifier = ml5.imageClassifier(imageModelURL); | ||
} | ||
|
||
function setup() { | ||
createCanvas(320, 260); | ||
// Create the video | ||
video = createCapture(VIDEO); | ||
video.size(320, 240); | ||
video.hide(); | ||
|
||
// Start classifying | ||
classifyVideo(); | ||
} | ||
|
||
function draw() { | ||
background(0); | ||
// Draw the video | ||
image(video, 0, 0); | ||
|
||
// Draw the label | ||
fill(255); | ||
textSize(16); | ||
textAlign(CENTER); | ||
text(label, width / 2, height - 4); | ||
} | ||
|
||
// Get a prediction for the current video frame | ||
function classifyVideo() { | ||
classifier.classify(video, gotResult); | ||
} | ||
|
||
// When we get a result | ||
function gotResult(error, results) { | ||
// If there is an error | ||
if (error) { | ||
console.error(error); | ||
return; | ||
} | ||
// The results are in an array ordered by confidence. | ||
console.log(results[0]); | ||
label = results[0].label; | ||
// Classifiy again! | ||
classifyVideo(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2019 ml5 | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
/* === | ||
ml5 Example | ||
Webcam Image Classification using a pre-trained customized model and p5.js | ||
This example uses p5 preload function to create the classifier | ||
=== */ | ||
|
||
// Global variable to store the classifier | ||
let classifier; | ||
|
||
// Label (start by showing listening) | ||
let label = "listening"; | ||
|
||
// Teachable Machine model URL: | ||
let soundModelURL = 'https://storage.googleapis.com/tm-speech-commands/eye-test-sound-yining/model.json'; | ||
|
||
|
||
function preload() { | ||
// Load the model | ||
classifier = ml5.soundClassifier(soundModelURL); | ||
} | ||
|
||
function setup() { | ||
createCanvas(320, 240); | ||
// Start classifying | ||
// The sound model will continuously listen to the microphone | ||
classifier.classify(gotResult); | ||
} | ||
|
||
function draw() { | ||
background(0); | ||
// Draw the label in the canvas | ||
fill(255); | ||
textSize(32); | ||
textAlign(CENTER, CENTER); | ||
text(label, width / 2, height / 2); | ||
} | ||
|
||
|
||
// The model recognizing a sound will trigger this event | ||
function gotResult(error, results) { | ||
if (error) { | ||
console.error(error); | ||
return; | ||
} | ||
// The results are in an array ordered by confidence. | ||
// console.log(results[0]); | ||
label = results[0].label; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Noting that for when this goes live we should retrain the example model so that we have one with the new TM style URLs.