I want to build a model which is able to detect the presence of a specific object in the image without caring about the location (i.e. no bounding boxes, just 0/1 output). More specifically, the object is always the same and it is characterized by a specific pattern (e.g. a national flag or a bar code). The algorithm should be robust to scale, rotation and distortion. What is the best architecture in this case? Is there something better than a generic CNN binary classifier?
It mostly depends on the amount of data you have available for training.
However, unless you have an extremely limited dataset and you are unable to generate synthetic data, CNNs are currently the best approach for solving your task. With sufficient data, they are very robust. To improve their performance, you can augment your dataset by randomly rotating, flipping, brightening, contrasting, scaling, cropping, blurring, and adding noise to the images throughout training.
It also depends on your speed requirements and computational resources. Traditional methods have the potential to be quite fast, but if you only care about accuracy, a deep network would probably perform better. Note that some CNNs are also quite fast, such as MobileNets.
There are a few reasons you might go "old school" and use template matching and more traditional approaches as suggested by @TheDjentleman:
- You do not have enough data to make a CNN robust AND you cannot generate synthetic data
- CNNs do not meet your speed requirements AND the traditional methods do
- You do not have sufficient resources to train a deep network, such as GPU(s). FYI Google developed a cloud computing tool for researchers and developers at a pretty reasonable cost.
If none of those criteria fit your situation, go with a CNN.
Lastly, you do not necessarily need a generic binary classification CNN. You can use an object detection network or even a semantic segmentation network and just ignore the location data if you do not need it.
May not really answer you question, but to be honest, if you just want to find one specific object that you know beforehand, I wouldn't use a neural network at all (in my opinion you should use the right tool for a task).
For easier tasks like this, you can use more "old school" methods (boo) like template matching. With such approaches you just take an isolated image of your object and, for example, extract a set of features (e.g. using opencv) and then move a rectangle over images where you want to find that object and just compare features. The advantage of such approaches is that you do not really need training data, like you would for training a neural network.
If you really, really, really want to use a CNN, you could try to just paste an image of your object into thousands of random images and then take even more images to train a classifier that examines if the object is in the image or not.
$\begingroup$ Thanks for your answer but I guess template matching is not able to generalize. :) $\endgroup$ Apr 23, 2018 at 9:18
$\begingroup$ I know, but if you just want to recognize one specific object, you don't really have to generalize too much. I agree, that it is a different story if you want your classifier to tell you if there is an object of a specific class (e.g. an apple) in your image $\endgroup$– nyro_0Apr 23, 2018 at 9:22
$\begingroup$ I forgot to mention that I am looking for a method which is invariant to scale, distortion and rotation. Can I achieve this with template matching? $\endgroup$– firionApr 23, 2018 at 12:21
$\begingroup$ I am not too much into this area any more, but I think you can make it invariant to scale and rotation (at least to some degree, at least he did it: youtube.com/watch?v=1M_JIfPRLao) by building image pyramids and using several templates of the same object. about the distortion, I can't really say anything about that, sorry $\endgroup$– nyro_0Apr 23, 2018 at 13:02
$\begingroup$ @TheDjentleman I didn't understand your task very well but search for spatial transformers. $\endgroup$ Apr 23, 2018 at 14:46