Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<html>
<head>
<!script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.5"></script>
<script>
var wait = ms => new Promise((r, j)=>setTimeout(r, ms));
window.onload = async function()
{
//'./model/model.json'
let path = './model/model.json'
const model = await tf.loadModel( path );
document.getElementById('image_upload').onchange = function(ev)
{
var f = ev.target.files[0];
var fr = new FileReader();
var makePrediction = async function(img)
{
document.getElementById('result').innerHTML = "Loading";
// 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([224,224]).toFloat().expandDims();
const prediction = model.predict(tensor);
var data = prediction.dataSync();
console.log( data );
document.getElementById('result').innerHTML = data[0] == 0 ? "That's a massive pigeon!" : "Not a pigeon";
}
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);
}
}
</script>
</head>
<body>
<h1>Pigeon?<hr/></h1>
<input id="image_upload" type="file"/></br>
<h3 id="result"></h3></br>
<img id="image" style="max-height: 500px"/>
</body>
</html>