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.
adds teachable machine image classification example (#196)
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
p5js/ImageClassification/ImageClassification_Teachable-Machine/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,20 @@ | ||
<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>Webcam Image Classification using a pre-trained customized model in Google's Teachable Machine and p5.js</h1> | ||
<p>If you cover your webcam, this model will classify it as "nighttime", | ||
otherwise will classify anything else else "daytime" </p> | ||
<script src="sketch.js"></script> | ||
</body> | ||
|
||
</html> |
1 change: 1 addition & 0 deletions
1
p5js/ImageClassification/ImageClassification_Teachable-Machine/model/metadata.json
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 @@ | ||
{"tfjsVersion":"1.1.2","tmVersion":"1.1.0","tmSupportVersion":"0.6.4","timeStamp":"2019-10-02T18:20:43.552Z","userMetadata":{},"modelName":"untitled","labels":["nighttime","daytime"]} |
1 change: 1 addition & 0 deletions
1
p5js/ImageClassification/ImageClassification_Teachable-Machine/model/model.json
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+2.05 MB
p5js/ImageClassification/ImageClassification_Teachable-Machine/model/weights.bin
Binary file not shown.
51 changes: 51 additions & 0 deletions
51
p5js/ImageClassification/ImageClassification_Teachable-Machine/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,51 @@ | ||
// Copyright (c) 2018 ml5 | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
/* === | ||
ml5 Example | ||
Webcam Image Classification using a pre-trianed customized model and p5.js | ||
This example uses p5 preload function to create the classifier | ||
=== */ | ||
|
||
// const checkpoint = 'model/model.json'; | ||
const checkpoint = 'https://storage.googleapis.com/teachable-machine-pubilshed-models/fa542ec0-b94b-4aa9-add4-c256963b0720/model.json'; | ||
let classifier; | ||
let video; | ||
let resultsP; | ||
|
||
function preload() { | ||
// Create a camera input | ||
video = createCapture(VIDEO); | ||
// Initialize the Image Classifier method with a pre-trained customized model and the video as the second argument | ||
classifier = ml5.imageClassifier(checkpoint); | ||
} | ||
|
||
function setup() { | ||
noCanvas(); | ||
// ml5 also supports using callback pattern to create the classifier | ||
// classifier = ml5.imageClassifier(checkpoint, video, modelReady); | ||
// If you would like to load the model from local files | ||
// classifier = ml5.imageClassifier('model/image-model.json', video, modelReady); | ||
resultsP = createP('Loading model and video...'); | ||
classifyVideo(); | ||
} | ||
|
||
// Get a prediction for the current video frame | ||
function classifyVideo() { | ||
classifier.classify(video, gotResult); | ||
} | ||
|
||
// If you use callback pattern to create the classifier, you can use the following callback function | ||
// function modelReady() { | ||
// console.log('Model Ready'); | ||
// classifyVideo(); | ||
// } | ||
|
||
// When we get a result | ||
function gotResult(err, results) { | ||
// The results are in an array ordered by confidence. | ||
resultsP.html('Label: ' + results[0].label + ' ' + nf(results[0].confidence, 0, 2)); | ||
classifyVideo(); | ||
} |