1
$\begingroup$

I have performed fruits classification using CNN but i am paused at a point where all things are going right confusion matrix accuracy score all are correct it seems there is no overfitting but it always classifies wrong fruit. Why would this happen. Link to source code is provided below. Thank You!

Github source code link

$\endgroup$
  • $\begingroup$ Are these new images? What is the prediction for one test image data? $\endgroup$ – 10xAI Jun 26 at 8:12
1
$\begingroup$

It looks like the new data has a different distribution from the training data. It looks like the training data is just a single fruit, with white background, and the new image you've passed is a picture of bananas with blue background. The model has probably learned something like: if blue image, then blueberries, and for this reason it classifies the blue bananas picture as blueberries.

Whenever the distribution of new data is different from the data you've trained on, don't expect the model to work very well, as ML models just interpolate.

| improve this answer | |
$\endgroup$
  • $\begingroup$ So i cannot do anything? It's dataset problem you mean? $\endgroup$ – Ganesh Kuikel Jun 26 at 7:12
  • $\begingroup$ Yeah, I think the dataset is the problem. If you want to predict for real pictures, you should have a dataset with real pictures. With a dataset with more variety of pictures, you won't have this issue. $\endgroup$ – David Masip Jun 26 at 7:20
  • $\begingroup$ I think you are correct when i try to predict with test dataset or new image that are same as training and testing dataset it is perfect on prediction but it is not good with multiple fruits in a image and i applied transfer learning and it was quite better than previous two models. $\endgroup$ – Ganesh Kuikel Jun 27 at 2:18
1
$\begingroup$

If your dataset is too small, it won't apply to other new data easily. In this case, you should either:

  1. try to increase your training dataset

    Find new images and classify them to increase the training data size, the model will improve as you add new images, but this can be time consuming

  2. use transfer learning

    Find a model that someone else built on a similar dataset and use that as a starting point for your model. They would have already found a large training dataset, built a model on that dataset, and saved the model to a public location for others to use and apply to new datasets. Need to find a model that is built on a dataset that is somewhat similar to your data.

  3. Data augmentation

    Can also help with #1, but you still need many images to train with.

Here is a good reference to use for transfer learning: https://machinelearningmastery.com/transfer-learning-for-deep-learning/

| improve this answer | |
$\endgroup$
  • $\begingroup$ I think there is some problem with my dataset it is learning something and predicting something. For example it is learning all same type of images so it could not identify when it comes to new images or multiple images but it is quite sure with test data and i had done data augmentation and i applied transfer learning using InceptionV3 and i found it predicts slightly better than previous two models. $\endgroup$ – Ganesh Kuikel Jun 27 at 2:15
  • $\begingroup$ In general, a good dataset can give good modelling results, a poor dataset will never give good modelling results. Since you are already using InceptionV3, maybe you can get some ideas from this page: towardsdatascience.com/… Keep in mind that transfer learning works best with images that are similar to the new images you provide to the model. Or you can try to download more images of fruit that is classified, such as here: data.mendeley.com/datasets/rp73yg93n8/1 or here: kaggle.com/moltean/fruits $\endgroup$ – Donald S Jun 27 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.