googlecreativelab / teachablemachine-community

Example code snippets and machine learning code for Teachable Machine
https://g.co/teachablemachine
Apache License 2.0
1.49k stars 665 forks source link

Issue using Image Classification with ML5 #96

Open hardikyjoshi opened 4 years ago

hardikyjoshi commented 4 years ago

When I try to manually classify a video using ml5's imageClassifier and Google Teachable Machine using vanilla javascript (not the p5.js). When I give it a model from the Google Teachable machine I get this error in console:

Screenshot 2020-04-01 at 20 18 44

I've used the latest version of ml5, 1.2.9 of tf.min.js and 0.8 for teachablemachine-image.min.js.

JSFiddle Link: https://jsfiddle.net/hardikj/e4kL5njs/

HalfdanJ commented 4 years ago

@shiffman and team, do you have a sense of what might have changed?

shiffman commented 4 years ago

I just tested with the latest ml5 and a newly trained model and it worked for me (no p5). Do you see anything different between yours and mine? Feel free to file an issue at https://github.com/ml5js/ml5-library

https://editor.p5js.org/codingtrain/sketches/ZTQ533aG0

// Grab elements, create settings, etc.
const video = document.getElementById('video');

// Create a webcam capture
navigator.mediaDevices.getUserMedia({ video: true })
  .then((stream) => {
    video.srcObject = stream;
    video.play();
  })

ml5.imageClassifier('https://teachablemachine.withgoogle.com/models/furopyvSe/model.json', video)
  .then(classifier => loop(classifier))

const loop = (classifier) => {
  classifier.classify()
    .then(results => {
      result.innerText = results[0].label;
      probability.innerText = results[0].confidence.toFixed(4);
      loop(classifier) // Call again to create a loop
    })
}