How to (not) get Poison Ivy, with AI! Part 2

Ben Burke
4 min readMay 6, 2023

--

Photo by Prudence Earl on Unsplash

Last article I talked about how I got poison ivy and vowed to never get it again.

So I put myself through some self-paced training (thanks fast.ai) and learned how to create my own poison ivy detector.

You can try it out here.

However, it wasn’t great.

Only 75% sure

Revamp

When I took it for spin outside this spring, flowers were blooming, tulips are emerging and the greenery was coming back. Because poison ivy can look very similar to so many other plants I didn’t want myself, or my kids, to be accidentally playing in some of it.

As you can tell from the examples, it does pretty well when there is just a single plant and the leaves are very pronounced. But when put up against a bunch of other leaves or plants, it got a little confused.

Boxelder plant getting mispredicted

I kept the same dataset I had gotten from Duck Duck Go (note: some images were different due to search returns) but I changed a few things:

  1. Preprocessing
  2. Model type

Pre Processing

There are many ways to preprocess images (squishing, resizing, rotating, add padding, etc.)

Left: original image, Right: Cropped, squished and resized
Padding example
Random Augmented Transformation (Cropping, brightness, stretching, squishing, flipping, cropping & padding)

My final implementation used random augmentation on the images. The feature increase the dataset size by a factor of x to allow for different versions of the same image to feed and teach the model.

I set mine to a factor of 3.

Model Architecture

Architecture is the next important factor. Here we are not defining how pipelines run, or how our app works, but the architecture of how the model itself was created.

While designing and developing ones own neural network and model can be an excellent learning opportunity, it also is fraught with many errors, hours or days of training, and months of design work. It’s typically done by those who are deep into research and development with machine learning and artificial intelligence and have advanced degrees.

But I’m a practitioner.

While I have designed NN in the past, I love creating usable applications quickly. And luckily for me (and you also) these sophisticated models built are available in the wild for open source.

However, there are many to choose from. How do can we pick the best one?

Fast.ai actually curated a list already of best performing models, as well as their fit_time and memory consupmtion. It can be found in their Kaggle notebook.

Top 14 performing models tested by Fast.ai

Since my dataset was small, GPU didn’t matter too much to me, but I was concerned about the nuances of the similarities of the plans. So I one with the smallest error rates: convnext_tiny_in22k.

With only 6 iterations, it took only 32 sec. to train and got down to an error rate of almost 4%. A vast improvement over the previous model, resnet18.

Left: resnet18, Right: convnext_tiny_in22k

We can see the training time did take slightly longer with convnext_tiny_in22k, though by mere seconds. If our training dataset were larger, this number would increase exponentially.

Result

We now have a new Poison Ivy Detector which is much faster and much better at predicting the noxious weed.

You can check out the new detector here.

Afterward

In this small series of articles we talked about the ease of creating our own image model to classify images, specifically poison ivy.

Next we discussed how fast.ai not only teaches but also curates it’s SDK to assist with model development and how hugging face facilitates hosting a model.

Finally, we showed how changing simple augmentation and model architecture can drastically improve model performance.

Stay safe out there!

Code available on my GitHub.

--

--

Ben Burke

I’m a Data Scientist who loves serving. I write about how businesses of all sizes can save time & money and make more money by harnessing data they already have