-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
63 lines (43 loc) · 1.89 KB
/
index.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
Load TensorFlow.js. This is required to use MobileNet.
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
<!-- Load the MobileNet model. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/[email protected]"> </script>
<!-- Replace this with your image. Make sure CORS settings allow reading the image! -->
<script type="text/javascript">
function draw(){
//이미지 객체 생성
var imgClo = new Image();
//페이지 로드후 이미지가 로드 되었을 때 이미지 출력
imgClo.addEventListener('load', function(){
//로드된 이미지를 캔버스에 출력
var ctx = document.getElementById('myCanvas').getContext("2d");
//canvas.drawImage() 함수를 사용하여 이미지 출력
//drawImage ( image sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
ctx.drawImage( imgClo , 0, 0, 200, 200);
},false);
//이미지 경로 설정
imgClo.src="cat.jpg";
}
</script>
<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
// Notice there is no 'import' statement. 'mobilenet' and 'tf' is
// available on the index-page because of the script tag above.
const img = document.getElementById('myCanvas');
console.log('loading...');
// Load the model.
mobilenet.load().then(model => {
// Classify the image.
model.classify(img).then(predictions => {
console.log('Predictions: ');
console.log(predictions);
predictions.sort((a,b) => {
return b.probability - a.probability;
});
console.log(predictions[0].className, '으로 판단되며, 정확도는 ', Math.round(predictions[0].probability*10000)/100, '% 입니다.');
});
});
</script>
<body onload="draw();">
<canvas id="myCanvas" height="200" width="200"></canvas>
</body>