Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yuqi's Lab7 #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
Binary file added 1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,138 @@
# lab07-machine-learning
## Name
Yuqi Zhang yuqiko 83234493

## Classifier
![](1.gif)

// 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://teachablemachine.withgoogle.com/models/Am_wraDzH/';


// Video

let video;

let flippedVideo;

// To store the classification

let cus_img;

let label = "";

// Load the model first

function preload() {

classifier = ml5.imageClassifier(imageModelURL + 'model.json');

}

function setup() {

createCanvas(320, 260);

// Create the video

video = createCapture(VIDEO);

video.size(320, 240);

video.hide();

cus_img = createImg("https://media2.giphy.com/media/qPoCDRpGkRG5a/giphy.gif?cid=ecf05e47bxcrp7xscr0dw7b70lbtipfzx23sjy9reurrpd6f&rid=giphy.gif&ct=g");

cus_img.hide();

flippedVideo = ml5.flipImage(video)

// Start classifying

classifyVideo();
}

function draw() {

background(0);

// Draw the video

image(flippedVideo, 0, 0);

// Draw the label

fill(255);

textSize(16);

textAlign(CENTER);

if(label == "Class 1"){

image(cus_img, 0, 0, cus_img.width*0.75, cus_img.height*0.75);

text("Togepi", width / 2, height - 4);

}else{

text("Togekiss", width / 2, height - 4);

}

}

// Get a prediction for the current video frame

function classifyVideo() {

flippedVideo = ml5.flipImage(video)

classifier.classify(flippedVideo, 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();
}



1. Create a brief demo with Teachable Machine
- Go to https://teachablemachine.withgoogle.com/
Expand Down