Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (40 sloc) 1.69 KB
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
</head>
<body>
<h1>NotHotdog<hr/></h1>
<input id="image_upload" type="file"/></br>
<h3 id="result"></h3></br>
<img id="image" style="max-height: 500px"/>
<script>
var wait = ms => new Promise((r, j)=>setTimeout(r, ms));
async function main() {
const model = await tf.loadModel('./model/model.json');
document.getElementById('image_upload').onchange = function(ev) {
var f = ev.target.files[0];
var fr = new FileReader();
var makePrediction = async function(img) {
// We need to ensure that the image is actually loaded before we proceed.
while(!img.complete) {
await wait(100);
}
var tensor = tf.fromPixels(img).resizeNearestNeighbor([150,150]).toFloat().expandDims();
const prediction = model.predict(tensor);
var data = prediction.dataSync();
document.getElementById('result').innerHTML = data[0] == 0 ? "Now, that's a hotdog! :)" : "Not hotdog! :(";
}
var fileReadComplete = function(ev2) {
document.getElementById('image').src = ev2.target.result;
var img = new Image();
img.src = ev2.target.result;
makePrediction(img);
};
fr.onload = fileReadComplete;
fr.readAsDataURL(f);
}
}
main();
</script>
</body>
</html>
You can’t perform that action at this time.