I am new in this field of machine learning, to test I wanted to do a simple project. Create a cnn capable of recognizing hamburger images. As I do not have the ability to collect more than 10,000 images of hamburgers I have used an existing model to train what I need ... I have used VGG16.

This is the notebook I am using, to do transfer learning. I am training the model in detecting cats and hamburgers. https://github.com/EsteveSegura/detecting-food/blob/master/src/BurgerCNN.ipynb

If the notebook does not load, the entire code is also here https://gist.github.com/EsteveSegura/2be156ba5431fc42fb8ac13eb0506c82


Cat: 1024 imgs

Burger: 1097 imgs


Cat: 416 imgs

Burger: 326 imgs

When I try to predict photos of hamburgers, it usually gives a good result ... But it also detects as burger photos of tacos (99% acuraccy). Is it an overfitting problem? Do I need more images? Am I doing the transfer learning in a correct way?

My goal will be to detect if there is a hamburger in the photo or not.

One of the recommendations they have given me is to train a third class with completely random objects that do not repeat ... Can this help? In case I can help? How?

This is the log of my training enter image description here


1 Answer 1


You are almost there as you mentioned the addition of third class as random photos. Generally what happens when you train a neural network, it assumes the entire domain of images existing as the training data. For your case each image can be either cat or burger. Now you have not shown random images to network and hence when a image which is neither cat nor burger, network will try it's best to predict it as either cat or burger. Instead I would suggest you to train network as burger vs not burger. In not burger class have all possible kind of images that are not burger. You can use CIFAR 1000 data to get images of different classes. Now your model will learn to differentiate between burger and not burger properly. Obviously you can still find some cases where miss classification happening and the reason will be because you have not covered such images in training.

Also play a bit with softmax threshold to get high presicion and recall.

  • $\begingroup$ So let's say that I want to create a bot on twitter that detects photos of hamburgers using machine learning, but I want to do it in the hashtag of #foodporn .... In that context the right thing would be to create a hamburger class and another class, with all kinds of food that does not include hamburgers? $\endgroup$
    – GiR
    Oct 17, 2019 at 17:21
  • $\begingroup$ Yes I think this should work. Here you will be needed to annotate images manually. Or see if you can leverage some existing food data. $\endgroup$ Oct 17, 2019 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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