googlecreativelab / teachablemachine-community

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

Prediction is not same as in Teachable web #315

Open ananthakrish98 opened 1 year ago

ananthakrish98 commented 1 year ago

When i tried to predict data using the exported saved model from teachable machine in my local using their suggested code, i couldn't get the same accuracy as that of teachable machine.

sryu1 commented 1 year ago

Hi @ananthakrish98 what snippet did you use?

sryu1 commented 1 year ago

if it was keras or opencv keras, I have a pull request open right now, and it should provide better results using the code snippet from the pending pr.

ananthakrish98 commented 1 year ago

I was using keras

sryu1 commented 1 year ago

Yeah take a look at my pull request or my tmc repository and try that code, if the predictions are still wrong, can you just show me what you get for the website then the code?

sryu1 commented 1 year ago

Did it work now @ananthakrish98?

sryu1 commented 1 year ago

The code snippet is now updated in the teachable machine website now.

ChoiBoHyeon commented 1 year ago

I have the same problem. Did you solve it?

sryu1 commented 1 year ago

Yes, it should be solved...

sryu1 commented 1 year ago

which snippet did you use?

ChoiBoHyeon commented 1 year ago

What is snippet? I am not good at English... sry..

sryu1 commented 1 year ago

A snippet is a example/small part of a code. The snippets for python are here: https://github.com/googlecreativelab/teachablemachine-community/tree/master/snippets/markdown/image/tensorflow

ChoiBoHyeon commented 1 year ago

I tested it with the opencv code of the link you sent me. But the recognition rate is still low.

sryu1 commented 1 year ago

So you tried both keras and opencv snippet? Keras may have a higher recognition rate, if opencv has a lower recognition rate, could you please tell me and I'll try to fix it.

ChoiBoHyeon commented 1 year ago

Yes, I've used both. This is a link that includes my project code and model. https://github.com/DCU-CapstoneDesign-WhiteCane/WhiteCane-AI

sryu1 commented 1 year ago

I'll take a look at that a bit later when I get the time to.

ChoiBoHyeon commented 1 year ago

Oh, thank you. Thank you for your kindness.

ChoiBoHyeon commented 1 year ago

Did you find a solution?

sryu1 commented 1 year ago

Hi, I did look through your code and nothing seems wrong... The only thing I'd suspect is most likely the teachablemachine code itself, since it originally uses tfjs, and when you get the keras model, it converts a tfjs model to a keras model and something might've gone wrong with that... I'm so sorry I wasn't able to help you much.

ChoiBoHyeon commented 1 year ago

I see. Thank you again for your kindness!

miminashi commented 1 year ago

I'm facing the same problem. I'm also using keras (not OpenCV)

sryu1 commented 1 year ago

Wow, ok, I'll take a look by trying it out when I get the time to.

sryu1 commented 1 year ago

Hi @ChoiBoHyeon @miminashi @ananthakrish98 Could you try the snippets from here? I updated some snippets and this might help.

miminashi commented 1 year ago

@sryu1 Thanks! I'll try it.

sryu1 commented 1 year ago

Does it work @miminashi?

Mallikarjun29 commented 1 year ago

@sryu1 I tried the keras snippets from your repository. I'm still facing the same problem. I think the problem is conversion from tfjs to keras model.

miminashi commented 1 year ago

@sryu1 I have not yet been able to test this quantitatively, but I cannot tell the difference in terms of experience. I am writing a test for my model right now. Please give me some time.

miminashi commented 1 year ago

According to @sryu1 's snippet, I modified my code and tested.

- image = ImageOps.fit(image, size, Image.Resampling.LANCZOS)
+ image = ImageOps.fit(image, size)

The entire source code is here: https://github.com/GUND-ARM/favrial/blob/main/ml/main.py

Test script here: https://github.com/GUND-ARM/favrial/blob/main/test_model.sh

Test steps:

I am an novice in machine learning, so please let me know if there are any problems with my testing methods.

Test Result:

epoch SULEMIO NOTSULEMIO SULEMIO(sryu1) NOTSULEMIO(sryu1)
50 0.79 0.75 0.79 0.75
60 0.65 0.86 0.67 0.85
80 0.67 0.86 0.70 0.85
100 0.69 0.87 0.66 0.87
150 0.74 0.81 0.71 0.80
200 0.76 0.81 0.72 0.84
250 0.71 0.80 N/A N/A
300 0.73 0.84 0.73 0.86

There did not seem to be much difference between the results with and without Image.Resampling.LANCZOS specified.

sryu1 commented 1 year ago

When you were testing it, did you record the results with the teachable machine's website results?

mohasaid commented 1 year ago

Hello,

I'm facing the same issue mentioned here, the prediction of my program is not the same as in the teachable web. In my case, I'm generating an audio model, then I convert it to a Keras model using tensorflowjs_converter (because I'm unable to download it as a Keras model) and I run it on a Python project.

Related to this issue I have two questions:

vish-n-u-k commented 4 months ago

I am also facing the same issue, I am using it for image recognition , it works perfectly on teachable web but in my app it sometimes fail. Should I train my model more would that help? Or should I do something else.