-
-
Save anonymous/400c3fc52db01860c1ddb8040bfcc4c9 to your computer and use it in GitHub Desktop.
deeplearn.js playground 1509994912630
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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