googlecreativelab / teachablemachine-community

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

Exported Keras Model classifying incorrectly #57

Closed Tailorware closed 4 years ago

Tailorware commented 4 years ago

The downloaded Keras model classifies images differently than the Online Version. Probably the Image preprocessing in the provided Python Snippet is different from the one used on the website.

I build a two-class classifier for 3-channel vibration data (represented as RGB images) that works perfectly in the online version of Teachable Machine. Impressive Work by the way! But if I export the model to Keras and try the same predictions in Google Colab it always predicts the same class. Link to Teachable Machine: https://teachablemachine.withgoogle.com/models/dhRmTcji/

Link to Colab: https://colab.research.google.com/drive/12LGL5LDGNdoESE7L7tyWYW-YakzNOOhF

The Colab Notebook also contains links to download training and test set.

This is most likely a preprocessing issue.

It would be great if you could have a look. Thank you in advance!

Tailorware commented 4 years ago

After reading https://github.com/googlecreativelab/teachablemachine-community/issues/3 I tried to normalize between -1 and 1, which improves the classification accuracy but it does not fix the problem entirely. The classfier is still wrong on half of the samples of the "bad" class.

Changed line of code: normalized_image_array = (image_array.astype(np.float32) / 127.0) -1

GautamBose commented 4 years ago

Hi! I went through your Colab, and noticed the same classification performance issue.

However, I trained a new model in teachable machine with images in the training folder you provided, re-exported to keras, and tried the test samples again with the corrected normalization between -1 and 1. The performance was accurate. I suspect the keras model loaded into the Colab isn't the most up to date with the one trained in TM.

I've modified the drive link in a copy of the Colab with my newly exported keras model here:

New Collab link

My TM model is here:

Retrained TM Model

The normalization is updated in the snippet: #58

Tailorware commented 4 years ago

Hi Gautam, thanks for solving this issue so quickly. You are right I had serveral model files and probably confused them.

Thanks again for the great work you have done!