5
$\begingroup$

So I'm trying to contruct a simple binary classifier.

Problem: Classify an image as containing the apple logo, or not.

I'd like it to be distortion, color, size and rotationally invariant. I'm sure that Classify[] should be able to handle this problem given the data. I have a set of positively and negatively labeled images you can download from this link, it's a file called PositiveAndNegativeAppleData.zip (about 20 mb).

Here's how to get my code going:

dir =(*path to dir containing unzipped folders*);

ndir = FileNameJoin[{dir, "negative"}];
pdir = FileNameJoin[{dir, "positive"}];

nfiles = FileNameJoin[{ndir, #}] & /@ Import[ndir];
pfiles = FileNameJoin[{pdir, #}] & /@ Import[pdir];

CloseKernels[]; LaunchKernels[16];
negative = ParallelMap[Import, nfiles];

positive = ParallelMap[Import, pfiles];

trainingData = <|"Apple" -> positive, "None" -> negative|>;

c = Classify[trainingData, 
  Method -> {"SupportVectorMachine", 
    "KernelType" -> "RadialBasisFunction", 
    "MulticlassMethod" -> "OneVersusAll"}, 
  PerformanceGoal -> "Quality"]

I still haven't been able to obtain a ClassifierFunction with high accuracy. I'd really appreciate some insight here, seems like a standard problem.

$\endgroup$
  • $\begingroup$ Why do you call it standard problem? There's no universal method to find high accuracy classifiers from image data (eg partial fingerprints matching - recently a $100k Innocentive challenge, ppl playing frisbee etc). $\endgroup$ – alancalvitti Jan 20 '15 at 23:32
  • $\begingroup$ One of the problem is your image sizes. In your training set negative images is considerably larger then positive. It can give undesirable dependence on the image size. If I understand correctly, the main problem is find the place of the logo in the big image. It is not what Classify do. May be a combination with MorphologicalComponents will give you better results. P.S. I'm not a professional in this area. $\endgroup$ – ybeltukov Jan 21 '15 at 0:12
  • $\begingroup$ Can you offer the datasets again? $\endgroup$ – HyperGroups May 11 '17 at 8:28
  • $\begingroup$ I don't have them anymore, just use flickr-32 instead $\endgroup$ – M.R. May 11 '17 at 19:59
4
$\begingroup$

Change a bit code, also are you sure <|"Apple" -> negative, "None" -> positive|> or did I misunderstood the problem? Anyways this seems logical (works same efficiently without ConformImages but I just wanted to feature it):

dir =(*path to dir containing unzipped folders*);

ndir = FileNameJoin[{dir, "negative"}];
pdir = FileNameJoin[{dir, "positive"}];

nfiles = Import[ndir <> "/*.png"];
pfiles = Import[pdir <> "/*.png"];

negative = ConformImages[nfiles, 200];
positive = ConformImages[pfiles, 200];

$train = 100;

trainingData = <|"Apple" -> positive[[;;$train]], "None" -> negative[[;;$train]]|>;
testingData = <|"Apple" -> positive[[$train+1;;]], "None" -> negative[[$train+1;;]]|>;

c = Classify[trainingData, 
   Method -> {"SupportVectorMachine", 
     "KernelType" -> "RadialBasisFunction", 
     "MulticlassMethod" -> "OneVersusAll"}, 
   PerformanceGoal -> "Quality"];

Magnify[{#, c[#]} & /@ 
Flatten[{RandomSample[positive[[$trainSize + 1 ;;]], 10], 
  RandomSample[negative[[$trainSize + 1 ;;]], 10]}] // Transpose // Grid, 0.5]

enter image description here

cm = ClassifierMeasurements[c, testingData];

cm["Accuracy"]

0.796954

cm["ConfusionMatrixPlot"]

enter image description here

Response to Answer

Thanks Vitalyi, great start, yes 79% is not terrible! Unfortunately, this is not working for any images that have real backgrounds. For example: enter image description here

What do we need to to to make the detector more robust to the logo signal? This is the heart of the problem!

$\endgroup$
  • 1
    $\begingroup$ It is interesting. But what about images being out of the training set? Is it possible to recognize something new? $\endgroup$ – ybeltukov Jan 21 '15 at 1:16
  • $\begingroup$ @ybeltukov yes, I updated the code to show that. Got even better results - accidentally of course. $\endgroup$ – Vitaliy Kaurov Jan 21 '15 at 1:20
  • 1
    $\begingroup$ Wow, incredible! $\endgroup$ – ybeltukov Jan 21 '15 at 1:24
  • $\begingroup$ Right, I had the positive and negative reversed... $\endgroup$ – M.R. Jan 21 '15 at 2:16
  • $\begingroup$ @VitaliyKaurov Ok so 79% accuracy is not so great, how can I do better? Also the classifier is not very good on finding images in the wild, see my edits. $\endgroup$ – M.R. Jan 21 '15 at 2:28

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.