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: