Advertisement
Guest User

index,js

a guest
May 17th, 2021
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PreviewImage() {
  2.     var oFReader = new FileReader();
  3.     oFReader.readAsDataURL(document.getElementById("image-selector").files[0]);
  4.  
  5.     oFReader.onload = function (oFREvent) {
  6.         document.getElementById("selected-image").src = oFREvent.target.result;
  7.         $("#prediction-list").empty();
  8.     };
  9. };
  10.  
  11. async function getPred(){
  12.     let image = $("#selected-image").get(0);
  13.     const model = await mobilenet.load();
  14.     const predictions = await model.classify(image);
  15.     //console.log(predictions);
  16.     predictions.forEach(function (p){
  17.         const className = p.className.split(',')[0];
  18.         const probability = (p.probability*100).toFixed(5);
  19.         $('#prediction-list').append('<li>'+className+' : '+probability+'</li>')
  20.     });
  21.  
  22. }
  23.  
  24. const img = new Image()
  25. img.src='https://image.shutterstock.com/image-vector/vector-illustration-unused-match-stick-260nw-1662505090.jpg';
  26. img.crossOrigin = "anonymous";
  27.  
  28.   // Load the model.
  29. mobilenet.load().then(mdl => {
  30.     // Classify the image.
  31.     mdl.classify(img).then(predictions => {
  32.       console.log('Predictions: ');
  33.       console.log(predictions);
  34.     });
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement