Skip to content

Instantly share code, notes, and snippets.

@B046090010
Last active March 7, 2022 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save B046090010/4d2d95b69b465fa6eff2e43db9f92aa8 to your computer and use it in GitHub Desktop.
Save B046090010/4d2d95b69b465fa6eff2e43db9f92aa8 to your computer and use it in GitHub Desktop.
<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<script src="https://unpkg.com/@tensorflow/tfjs-automl"></script>
<p><input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none;"></p>
<p><label for="file" style="cursor: pointer;">Upload Image</label></p>
<p><img id="output" width="200" /></p>
<p><pre id = "result"></pre></p>
<script>
async function run() {
const model = await tf.automl.loadImageClassification('api_list/model.json');
const image = document.getElementById('output');
const predictions = await model.classify(image);
console.log(predictions);
// Show the resulting object on the page.
const result = document.getElementById('result');
result.textContent = JSON.stringify(predictions, null, 2);
}
var loadFile = function(event) {
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
run();
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment