-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
56 lines (47 loc) · 1.75 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
<!-- 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>
<html>
<body>
<input type='file' id='image-file' accept="img/jpg img/png" />
<button id='sbButton'>Submit</button>
<div>
<img id='image' width="512" height="512"/>
<dl>
<dt>ClassName</dt>
<dd id="classname"></dd>
<dt>Confidence</dt>
<dd id="confidence"></dd>
</dl>
</div>
</body>
</html>
<script>
document.getElementById("sbButton").addEventListener("click", onImageSubmit)
function onImageSubmit(){
var img = document.getElementById("image")
var file = document.getElementById("image-file")
img.setAttribute("src", "./asset/"+file.files[0].name)
mobilenet.load().then(model => {
model.classify(img).then((predictions) => {
var res = predictions[0]
console.log(res)
console.log(res.className)
var classname = document.getElementById("classname")
var confidence = document.getElementById("confidence")
classname.innerHTML = res.className
confidence.innerHTML = res.probability
})
})
}
// const img = document.getElementById('img');
// // Load the model.
// mobilenet.load().then(model => {
// // Classify the image.
// model.classify(img).then(predictions => {
// console.log('Predictions: ');
// console.log(predictions);
// });
// });
</script>