Message Boards Message Boards

GROUPS:

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

Posted 4 years ago
8644 Views
|
4 Replies
|
23 Total Likes
|

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:

enter image description here

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:

enter image description here

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

enter image description here

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:

enter image description here

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

enter image description here

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

enter image description here

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:

enter image description here

You can look at the estimated probabilities of each classification:

enter image description here

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:

enter image description here

4 Replies

Hi Arnoud! This is fun :)

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|>

Training Set

 LionOrTigerOrBear = Classify[trainingset]

Classifier

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

Tiger

What about the Teddy Bear?

teddy bear

Good job!

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!

enter image description here - 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!

Posted 3 years ago

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?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract