I'm getting the following error messages (sketch.js:47 Error: pixels passed to tf.fromPixels() can not be null) when starting to classify after loading a previously trained model. The classifier is working fine and it guesses the right images based on the previously trained data so I'm not sure why it returns that the images are null because it definitely read them correctly somehow.
Screenshot of the error messages:

I'm getting as many error messages as images I trained the model with, but the classifier works fine, so I'm a bit confused. And the weirdest thing is that roughly 1 out of 10 times it actually doesn't return any error message at all. UPDATE: Instead of starting to classify on the callback after loading the custom model I added a button that only shows up if a custom model is loaded. Using that button to start classifying doesn't produce any error message and works without any issues at all. The problem is solved for me but I guess it shouldn't return any error message when called on the classifier.load() callback so that's why I'm opening the issue anyway.
I'm serving the sketch and the model files with a nodejs script running an express server.
I get the same error & the solution above hasn't worked for me. :(
same for me, if anyone could provide a solution to this it would be much appreciated
@bgree052 I found that switching from Firefox to Chrome solved this for me. Hope this helps.
@bgree052 is Firefox the issue? I am not able to reproduce this error. (Also, I am running the current build of the library which will be released to npm shortly.)
@shiffman I am having the same issue with Firefox, Safari, and Chromium. I am using [email protected]
For those that are seeing this error and were following the @shiffman tutorial, it's related to a race condition in the sample code. You may notice the Video is ready output show up after the error in your console. So the video isn't ready and you are trying to classify. Move this line
classifier.classify(gotResults);
to the videoReady callback function..
Thanks @davidkarim! I'll take a look at the examples and make sure they wait for the video to be ready. Hopefully more support for preload #288 will help reduce this kind of confusion!
This is the same comment I put on 55, but it returns the same error so maybe it is related to this?
I'm getting an error adding images, training, and loading custom models in my website when on iOS.
The errors I get are:
And I did look at error #241, but that solution did not work. It seems like an issue with how the feature extractor and classification work with iOS?
Sorry for me typing out the errors I wrote it done from work, but might update this if need be!
For those that are seeing this error and were following the @shiffman tutorial, it's related to a race condition in the sample code. You may notice the Video is ready output show up after the error in your console. So the video isn't ready and you are trying to classify. Move this line
classifier.classify(gotResults);to the videoReady callback function..
@davidkarim : I faced the same issue it's strange that in Chrome it's working fine but firefox is still giving the same issue even after calling it after videoReady. my best guess is for some reasons firefox is not passing the video pixels to tensorflow for some reasons but couldn't able to make any progress.
I get the same problem on iOS (Safari, chrome wont even load my webcam stream), is there no way to make it work on iOS? My custom model was made by chrome on a PC.
@shiffman upgrading from ml5 version: 0.1.3 to 0.3.1 solved the firefox issue also best part is now the classify() function is returning object with confidence instead of just label, thanks for the awesome easy to grasp tutorials you create :)
0: Object { label: "sad", confidence: 0.9504269957542419 }
1: Object { label: "happy", confidence: 0.04957294091582298 }
length: 2
@annvnzndrvn I think this might be an issue of synchronization. I was having the same issue. It turned out that the code was classifying the image before the image was properly loaded.
If you are passing a p5 image element, then call the classifier in its success callback and if you are passing an HTML image element, then set the classifier to the img.onload property of the image element
I got the same error message when I tried to follow @shiffman webcam image classification tutorial. I did a quick test and delayed the call to the classify method until I clicked on the canvas (model and video were loaded). It did not solve the problem. I got the same error.
I also did not get the error when classifying a static image.
@jindustry can you paste the code snippet so we can have a better look at it?
@plat2eau I figured out the problem. I was using an old version of the p5 libraries. Once I updated the p5 libraries, the image classification worked as expected.
To follow @shiffman's tutorial more closely, I watched his p5 workflow video. I installed the p5-manager node package to create a p5 project, but the new p5 project was created with old p5 libraries. Running "p5 update" solved the problem. Note this step is not mentioned in the workflow tutorial video.
Hi All,
I will close this issue for now. Please make sure to use the latest version of ml5 - 0.3.1- and the latest p5 version - 0.9.0.
Thanks for you participation!
I came across the same problem,
I think its my Lantern vpn result in this,
Because when I disconnect my vpn, problem gone.
But its too slowly, I had not gor any good solution for it.
Most helpful comment
For those that are seeing this error and were following the @shiffman tutorial, it's related to a race condition in the sample code. You may notice the Video is ready output show up after the error in your console. So the video isn't ready and you are trying to classify. Move this line
to the videoReady callback function..