-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsub.js
68 lines (61 loc) · 2.4 KB
/
sub.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
// the link to your model provided by Teachable Machine export panel
const URL = 'https://teachablemachine.withgoogle.com/models/UR710TVEf/';
let model, webcam, labelContainer, maxPredictions;
// Load the image model and setup the webcam
async function init() {
const modelURL = URL + 'model.json';
const metadataURL = URL + 'metadata.json';
// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// or files from your local hard drive
// Note: the pose library adds "tmImage" object to your window (window.tmImage)
model = await tmImage.load(modelURL, metadataURL);
maxPredictions = model.getTotalClasses();
// append elements to the DOM
labelContainer = document.getElementById('label-container');
for (let i = 0; i < maxPredictions; i++) {
// and class labels
labelContainer.appendChild(document.createElement('div'));
}
}
// run the webcam image through the image model
async function predict() {
// predict can take in an image, video or canvas html element
// predict can take in an image, video or canvas html element
var image = document.getElementById("face-image")
const prediction = await model.predict(image, false);
prediction.sort((a, b) => parseFloat(b.probability) - parseFloat(a.probability));
console.log(prediction[0].className);
var resultMessege;
switch(prediction[0].className) {
case "알엠":
resultMessege = "RM과 닮음"
break;
case "진":
resultMessege = "진과 닮음"
break;
case "슈가":
resultMessege = "슈가와 닮음"
break;
case "제이홉":
resultMessege = "제이홉과 닮음"
case "지민":
resultMessege = "지민과 닮음"
break;
case "뷔":
resultMessege = "뷔와 닮음"
break;
case "정국":
resultMessege = "정국과 닮음"
break;
default:
resultMessege = "누구와도 닮지 않음"
}
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className + ": " + prediction[i].probability.toFixed(2);
labelContainer.childNodes[i].innerHTML = classPrediction;
}
}