Lions, or tigers, or bears? Oh my!!!

With the release of the new Wolfram ImageIdentify site, I decided try to make a mini version of this directly
in the Wolfram Language using the Classify function. The ImageIdentify web site is capable of identifying about
10,000 entities, but I set a more modest goal of identifying just three entities: Lion, or Tiger, or bear? (Oh my!!!).

To start off we need sample images of many lions, tigers, and bears. A simple way to get those images, is to use an
image search tool, like Microsoft’s Bing image search. Simply drag ten or more representative images from your browser
into Mathematica or save the images and Import them. You should end up with three lists like this:

Next, we need to write the classification code. We can call Classify which each category:

LionOrTigerOrBear = Classify[ <|
  "lion" -> lions,
  "tiger" -> tigers,
  "bear" -> bears
|> ]

And that’s it for the setup part! Now we’re ready to try out if things are working.

Here is a test case with an image of a bear that is not in the original training data:

The classifier found a match! Next, is an image of a tiger running through some water:

This is failing, possibly because the training images did not have a good matching image. And
possibly, the result is a ‘bear’ because some bear images have water in the background. Whatever
the underlying reason, the solution is to add more images to the training data (the more images you train with
the better the results).

To make sure that tigers can be identified let’s use an image of another tiger, resting in some grass:

This worked! And not to leave out the lions, let’s do an image of those as well:

Of course, you can give the LionOrTigerOrBear function an image of a lion, a tiger and a bear and see what happens:

In this case, the classifier picked bear. And it is interesting to note that this algorithm always picks one of the three choices, even if you feed it
an image of something that is neither a lion, a tiger, nor a bear:

You can look at the estimated probabilities of each classification:

Since ‘tiger’ scored the highest (with a estimated likelihood of about 81%) it gets returned as the top pick. To make the classfier
say “I don’t know” you can add a threshold, below which the result will be Indeterminate:

14 Likes

Hi Arnoud! This is fun :slight_smile:

I used Wildscreen Arkive to build a larger training set for your LionOrTigerOrBear classifier. Here is the code:

urls = {"http://www.arkive.org/lion/panthera-leo/photos.html", 
          "http://www.arkive.org/tiger/panthera-tigris/photos.html", 
          "http://www.arkive.org/brown-bear/ursus-arctos/photos.html"}; 

trainingset = <| StringSplit[#, "/"][[4]] -> Drop[Import[#, "Images"], 1] & /@urls|>

 LionOrTigerOrBear = Classify[trainingset]

The good news is that now LionOrTigerOrBear is correctly identifying the image of the tiger running through some water:

What about the Teddy Bear?

Good job!

7 Likes

Nice examples!

Could we automate the image import from Bing or similar, and just leave the computer learning unattended? Even better, with some kind of topic evolution, by following the most common nouns from a zoo page or similar?

I’m conscious that we are still far from having a common pc capable of navigating the internet, learning all sorts of things as it/he/she goes… But I would love to see an example of what can already be done, even if limiting to a set of nouns from a dictionary, or starting from that… and obviously, with Mathematica!

2 Likes

2015-11-02_10-07-11.png

  • another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the top of the “Featured Contributor” board. Thank you for your wonderful contributions, and please keep them coming!

Very interesting post for machine learning!

I have a question, how many images for training is enough to recognize a class as a human common sense level? Arnoud Buzing used about 10 images for each class, Bernat Espigulé Pons use about 100 images. So 100 images is good enough as minimal training level?