Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageClassifier does not throw an error when image is not found #396

Open
hx2A opened this issue May 28, 2019 · 1 comment
Open

ImageClassifier does not throw an error when image is not found #396

hx2A opened this issue May 28, 2019 · 1 comment

Comments

@hx2A
Copy link

hx2A commented May 28, 2019

When I follow the example on the Hello ml5 page:

https://ml5-website-2.netlify.com/getting-started/hello-ml5/

If the image to be classified is not found, p5's loadImage function will fail and log an error in the console. The img variable will not contain a valid image.

When classifier.classify(img, gotResult); is called in the setup method it should trigger an error because the image is not valid. However, in the gotResult method, this code:

  if (error) {
    console.error(error);
  }

is not executed. The error you see logged in the console is from p5, not ml5. If I change the function to this:

// A function to run when we get any errors and the results
function gotResult(error, results) {
  // Display error in the console
  if (error) {
    console.error(error);
    console.log('error');
    createDiv('Error running image classifier. View JavaScript console for details.');
  } else {
    // The results are in an array ordered by confidence.
    console.log(results);
    console.log('no error');
    createDiv('Label: ' + results[0].label);
    createDiv('Confidence: ' + nf(results[0].confidence, 0, 2));
  }
}

I see no error in the console.

Chromium Version 73.0.3683.103 (Official Build) Built on Ubuntu , running on Ubuntu 19.04 (64-bit) using ml5 0.3.0.

You can reproduce this by following the Getting Started tutorial but use an invalid image path.

@lindapaiste
Copy link
Contributor

There is more discussion of this issue in #1193. The changes to callCallback in #1307 should help.

I will take a look and make sure that we are throwing an appropriate error when passing in a p5 image which has failed to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

4 participants