-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI_Animaltest.html
197 lines (170 loc) · 6.62 KB
/
AI_Animaltest.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>인공지능 동물상 테스트</title>
<link rel="stylesheet" href="AI_Style.css">
<link rel="shortcut icon" herf="favicon.ico" type="image/x-icon">
</head>
<body>
<div class="header">
<h1>
동물상 테스트
</h1>
<h3>
얼굴로 보는 인공지능 동물상 테스트
</h3>
</div>
<div class="container">
<div id="upload-area" class="area">
<span class="guide-image">📸</span>
<br/>
<span>사진을 올려놓거나 눌러서 업로드해 주세요</span>
<input id="upload_input" style="display: none;"type="file" accept="image/*" onchange="readFile(this.files[0])"/>
</div>
<div id="share-area" class="area">
<h3>
동물상 테스트 공유하기
</h3>
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_inline_share_toolbox"></div>
</div>
<div id="loading-area" class="area" style="display: none;">
<span class="guide-image">🏃~</span>
<br />
<span>인공지능 모델을 불러오는 중입니다...</span>
</div>
<div id="result-area" class="area" style="display: none;">
<img id="upload-image" src="#" alt="your image" />
<div id='label-container'></div>
</div>
<div id="retry-area" class="area" style="display:none;">
<span>다른 사진으로 테스트하려면 눌러 주세요!</span>
</div>
</div>
<div id="webcam-container"></div>
<div id="disqus_thread"></div>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/[email protected]/dist/teachablemachine-image.min.js"></script>
<script type="text/javascript">
// 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/A8_Cr5Mcu/";
let model, webcam, labelContainer, maxPredictions;
let isModelReady=false;
let input=document.getElementById("upload_input");
let image = document.getElementById("upload-image");
let uploadArea=document.getElementById("upload-area")
let loadingArea = document.getElementById("loading-area");
let resultArea=document.getElementById("result-area");
let retryArea=document.getElementById("retry-area");
let shareArea=document.getElementById("share-area")
const reader=new FileReader();
async function readFile(file){
uploadArea.style.display="none";
shareArea.style.display="none";
if (isModelReady===false){
loadingArea.style.display="block";
await init();
}
reader.readAsDataURL(file);
}
reader.onload=async function(event){
await image.setAttribute('src',event.target.result);
await predict();
loadingArea.style.display="none";
resultArea.style.display="block";
retryArea.style.display="block";
};
uploadArea.onclick=function(){
input.click();
}
uploadArea.ondragover=function(event){
event.preventDefault();
}
uploadArea.ondrop=function(event){
event.preventDefault();
const file=event.dataTransfer.files[0];
readFile(file);
}
retryArea.onclick=function(){
retryArea.style.display="none";
resultArea.style.display="none";
uploadArea.style.display="block"
shareArea.style.display="block"
input.value="";
}
// 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();
// Convenience function to setup a webcam
labelContainer = document.getElementById("label-container");
for (let i = 0; i < maxPredictions +1; 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
const prediction = await model.predict(image);
prediction.sort((x,y)=>y.probability-x.probability);
switch (prediction[0].className){
case"Dog":
labelContainer.childNodes[0].innerHTML="<h3>당신은 강아지상!</h3>"
break;
case"Mouse":
labelContainer.childNodes[0].innerHTML="<h3>당신은 쥐상!</h3>"
break;
case"Cat":
labelContainer.childNodes[0].innerHTML="<h3>당신은 고양이상!</h3>"
break;
case"Horse":
labelContainer.childNodes[0].innerHTML="<h3>당신은 말상!</h3>"
break;
case"Pig":
labelContainer.childNodes[0].innerHTML="<h3>당신은 돼지상!</h3>"
break;
default:
labelContainer.childNodes[0].innerHTML="<h3>오류 발생</h3>"
break;
}
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className + ": " + Math.round(prediction[i].probability * 100)+"%";
labelContainer.childNodes[i+1].innerHTML = classPrediction;
}
isModelReady=true;
}
</script>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables */
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://dongmulsang-teseuteu-fm9at9oyog.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<script id="dsq-count-scr" src="//dongmulsang-teseuteu-fm9at9oyog.disqus.com/count.js" async></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-636f35e025253992"></script>
</body>
</html>