Skip to content

Commit facaf1d

Browse files
committed
해커톤
1 parent 79717d1 commit facaf1d

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

Diff for: index.html

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
<div>Teachable Machine Image Model</div>
9+
<button type="button" onclick="init()">Start</button>
10+
<div id="webcam-container"></div>
11+
<div id="label-container"></div>
12+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
13+
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/[email protected]/dist/teachablemachine-image.min.js"></script>
14+
<script type="text/javascript">
15+
// More API functions here:
16+
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
17+
18+
// the link to your model provided by Teachable Machine export panel
19+
const URL = "./my_model/";
20+
21+
let model, webcam, labelContainer, maxPredictions;
22+
23+
// Load the image model and setup the webcam
24+
async function init() {
25+
const modelURL = URL + "model.json";
26+
const metadataURL = URL + "metadata.json";
27+
28+
// load the model and metadata
29+
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
30+
// or files from your local hard drive
31+
// Note: the pose library adds "tmImage" object to your window (window.tmImage)
32+
model = await tmImage.load(modelURL, metadataURL);
33+
maxPredictions = model.getTotalClasses();
34+
35+
// Convenience function to setup a webcam
36+
const flip = true; // whether to flip the webcam
37+
webcam = new tmImage.Webcam(200, 200, flip); // width, height, flip
38+
await webcam.setup(); // request access to the webcam
39+
await webcam.play();
40+
window.requestAnimationFrame(loop);
41+
42+
// append elements to the DOM
43+
document.getElementById("webcam-container").appendChild(webcam.canvas);
44+
labelContainer = document.getElementById("label-container");
45+
for (let i = 0; i < maxPredictions; i++) { // and class labels
46+
labelContainer.appendChild(document.createElement("div"));
47+
}
48+
}
49+
50+
async function loop() {
51+
webcam.update(); // update the webcam frame
52+
await predict();
53+
window.requestAnimationFrame(loop);
54+
}
55+
56+
// run the webcam image through the image model
57+
async function predict() {
58+
// predict can take in an image, video or canvas html element
59+
const prediction = await model.predict(webcam.canvas);
60+
for (let i = 0; i < maxPredictions; i++) {
61+
const classPrediction =
62+
prediction[i].className + ": " + prediction[i].probability.toFixed(2);
63+
labelContainer.childNodes[i].innerHTML = classPrediction;
64+
}
65+
}
66+
</script>
67+
68+
</body>
69+
</html>

Diff for: my_model/metadata.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"tfjsVersion":"1.3.1","tmVersion":"2.2.2","packageVersion":"0.8.4","packageName":"@teachablemachine/image","timeStamp":"2020-10-31T01:18:50.886Z","userMetadata":{},"modelName":"tm-my-image-model","labels":["말티즈","시베리안 허스키","포메라니안","불독","묘크셔테리어","골든 리트리버","진돗개"]}

Diff for: my_model/model.json

+1
Large diffs are not rendered by default.

Diff for: my_model/weights.bin

2.06 MB
Binary file not shown.

0 commit comments

Comments
 (0)