-
-
Save hpssjellis/05af4e9e3e11f6e38b40b412926fa7cc to your computer and use it in GitHub Desktop.
deeplearn.js playground 1509994912630
This file contains hidden or 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
| <h1 align=center>SqueezeNet Cat Demo</h1> | |
| Trying to dynamically load an image but running into corssorigin issues. | |
| Have had some suuccess with <br> | |
| //https://crossorigin.me/your-URL<br><br> | |
| https://www.what-dog.net/Images/faces2/scroll001.jpg <br> | |
| but then how to re-activate the script. It does not seem to have a way to call it<br> | |
| <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 ><br><br> | |
| <input id="myFile01" type=text size=100 value='https://storage.googleapis.com/learnjs-data/images/cat.jpeg' onChange="{ | |
| // document.getElementById('cat').onload = function() { | |
| // context.drawImage(this, 40, 40); | |
| //}; | |
| // document.getElementById('cat').crossOrigin = 'Anonymous'; | |
| document.getElementById('cat').crossOrigin = 'Use-Credentials'; | |
| document.getElementById('cat').src = this.value | |
| document.getElementById('myDivOut').innerHTML = '' // clear the div | |
| }"><br><br> | |
| <div id="myDivOut">...</div> | |
| <input type=button value=try onclick="{ | |
| document.getElementById('myDivOut').innerHTML = '' // clear the div | |
| document.getElementById('cat').outerHTML = '<img id=\'cat\' src=\'https://www.what-dog.net/Images/faces2/scroll001.jpg\' width=227 height=227 crossorigin >' | |
| }"> | |
This file contains hidden or 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(); | |
| const squeezeNet = new squeezenet.SqueezeNet(math); | |
| await squeezeNet.load(); | |
| const image = dl.Array3D.fromPixels(catImage); | |
| const inferenceResult = await squeezeNet.predict(image); | |
| const topClassesToProbs = await squeezeNet.getTopKClasses(inferenceResult.logits, 10); | |
| document.getElementById('myDivOut').innerHTML = '' // clear the div | |
| for (const className in topClassesToProbs) { | |
| document.getElementById('myDivOut').innerHTML += topClassesToProbs[className].toFixed(5) + ' : '+ className + '<br>' | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment