Skip to content

Instantly share code, notes, and snippets.

/html

Created November 6, 2017 19:01
Show Gist options
  • Save anonymous/400c3fc52db01860c1ddb8040bfcc4c9 to your computer and use it in GitHub Desktop.
Save anonymous/400c3fc52db01860c1ddb8040bfcc4c9 to your computer and use it in GitHub Desktop.
deeplearn.js playground 1509994912630
<script src='https://unpkg.com/deeplearn-squeezenet'></script>
<img id='cat' src='https://storage.googleapis.com/learnjs-data/images/cat.jpeg' width=227 height=227 crossorigin>
const catImage = document.getElementById('cat');
const math = new dl.NDArrayMathGPU();
// squeezenet is loaded from https://unpkg.com/deeplearn-squeezenet
const squeezeNet = new squeezenet.SqueezeNet(math);
await squeezeNet.load();
// Load the image into an NDArray from the HTMLImageElement.
const image = dl.Array3D.fromPixels(catImage);
// Predict through SqueezeNet.
const inferenceResult = await squeezeNet.predict(image);
// Convert the logits to a map of class to probability of the class.
const topClassesToProbs =
await squeezeNet.getTopKClasses(inferenceResult.logits, 10);
for (const className in topClassesToProbs) {
console.log(
`${topClassesToProbs[className].toFixed(5)}: ${className}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment