My original question was posted on SE: How can I train a binary classifier to find a logo?, Vitaliy graciously answered it, but he suggested that since I need a more complete answer, I should try here on the Wolfram Community instead.
The Challenge
Part #1: Construct a logo detector that will find the logo of the Apple Inc. in a photo.
Here are a few clarifying points:
The output is whether or not the image contains the apple logo, with a confidence level.
The program should use HOG features and an Support Vector Machine classifier.
The classifier needs to be invariant to rotations, deformations, distortions, and translations.
I’ve attached my notebook from the initial stack-exchange post to get you started.
Note: The images are taken from Twitter, Tumblr, Instagram, and Google image search, so the algorithm when running in the wild will need to have good sensitivity, since only roughly 5% of these images have logos in them.
Part #2:
Added requirements:
Needs to find the bounding box of the logos.
Needs to handle images that have multiple logos
Needs to classify fast (within 10 to 100 milliseconds).
Part #3:
Extend this to more logo brands (e.g. pepsi), I will assemble and post the training and test data for you, if anyone can get this far…
Questions & Notes
I have read up on the literature on HOG training, but I can’t figure out what the best practices are for cropping the positive examples. Do you crop tight or with margins on the “object”? Do you crop all positive image to a standard aspect ratio or to whatever rectangle fits the appearance of the object in the particular image?
I took me a very long time to cull the datasets for training and testing, this python script helped, what free tools are there for this, specifically for cropping the logo out?
I have tried OpenCV cascades from HOG features, how much different will these be from an linear or nonlinear SVM classifier’s performance?
It’s entirely unclear how Mathematica handles the sliding windows across the images… this might have to be done with manual code, and if so, the literature seems to suggest that something in the range of 4x4 to 32x32 are the best.
The HOG features are not explicitly computed. Wouldn’t it be nice if ImageKeypoints had other (free) methods like HOG, BRISK, ORB, GIST, …
Mathematica notebooks quickly become unstable when they have too many images in them, any suggestions for getting around this besides DumpSave[]ing everything…
This really could be the coolest real world example of image processing + machine learning in Mathematica, and prove to the world that it is a professional toolbox for vision, which unfortunately many academics do not accept yet!
But is not your testing data (apple small buried in the background) are quite different from your training set (apple is image-sized - no background influence) ?
A preprocessing possibility might be to use feature extraction and cropping to find candidate subimages that could perhaps match. Whether this would work well would depend on how likely the feature extraction is to get the right subimages, and how many such
get produced.
From what people telling me you are asking about a research level problem. Some suggest some sort of partitioning of large images into smaller ones to get the logo but this would slow down the total time. Also orientations, deformations, distortions, and translations of the images matter. Did you search for any research papers on the subject? I am sure there are some general approaches. Have you seen THIS?
I am not sure whether that helps but I get rather good results. I am not sure how many images you have used for the training but with my training sets, the results are ok.
I must admit though that there are also quite a number of images that are false positives - if often mistakes trees for the logo. I think that this could be mended by using a larger image database. Also, if the logo is only a tiny part of the overall image that can cause problems - but reasonably small logos seem to work.
Once the classifier is trained, the classification takes only 0.02 seconds on my machine.
Cheers,
M.
PS: Occasionally, I get quite abysmal results. For some datasets I get rather good results. So this is by no means “ready-to-use”.
This is not research level by any means, and it is really trivial to do with many other vision systems. One could train a cascade on HOG feature points in 3 hours to have a classifier running on a gpu in OpenCV…
Can you please post the training and test set you are using? And FYI, I provided my original training and test set… it is hyperlinked to my question!