Evan Jones

fastai Fun

Worm

I have a tortoiseshell cat named Worm, whose patchy brown and golden fur resembles the haphazardly charred skin of a rotisserie chicken. My wife and I often remark during her loafs that "dinner's ready to come out of the oven!"

A photo of a cat on a windowsill

When I learned that it was quite easy to train and deploy machine learning models using fastai, I knew it was time to get a cursory, high-level understanding of how a very simple AI agent is trained to classify images by teaching a computer how to differentiate a cat from a rotisserie chicken and testing it with the most chicken-like photos of Worm.

fastai

fastai is well-maintained library of machine learning components that can be interfaced with at a high level. This allows people like myself, with no background in the advanced concepts undergirding machine learning, to have fun with deep learning models. In this case, I decided to use fastai's "vision learner" model, which is "pretrained" on over a million images.

Tuning and testing the model

While the pretrained model is very good, I wanted to tune it a bit so it was more accurate for my test of how much Worm looks like a rotisserie chicken. I grabbed 30 images each from DuckDuckGo of cats and rotisserie chickens and stored them in the virtual machine running my code:

After getting the images, I ran a quick check using a function from fastai to make sure that they all downloaded correctly:

Then, I got set up for fine-tuning by establishing a training set and a validation set. A machine learning model goes through several phases in its development — first, it learns the characteristics of the thing it's looking for by looking at the training set; then, the assumptions it's created are measured with the validation set.

From there, all I needed to do was train the model to update its classification abilities, which I could do in two lines:

Testing my best Worm photo

In order to test my most chicken-like photo of Worm, my last step was to allow users to upload an image file to be evaluated by the fine-tuned model:

I tested it with a few normal-looking photos of cats (and rotisserie chickens), which the model correctly classified with perfect accuracy. Finally, after being assured that the model was competent at making judgments, I fed it one peculiar Worm photo:

To my surprise, this photo nearly tricked the model! The lighting, the haunches, and the lack of a clear view of Worm's head were able to confuse the otherwise sure model, confirming my wife's and my characterizations of our cat's appearance.