Web AI App for Gardeners: Centipedes vs Millipedes

ML Model Deployment with fastai and Binder

Centipedes and millipedes are two creatures that one can encounter in the garden. Centipedes are beneficial to you because they feed on mites, insect larvae, insects, baby snails, and slugs. Millipedes, on the other hand, can be harmful and feed on plant roots, germinating seeds, and seedlings. Therefore it is beneficial to any gardener to be able to distinguish between the two.

Being inspired by the beautiful book “Deep Learning for Coders with fastai and PyTorch: AI Applications Without a PhD” by Jeremy Howard and Sylvain Gugger, I decided to make a simple AI app for my wife, who is an avid gardener, that would help with the classification of centipedes and millipedes.

Dataset: I used Microsoft Bing Image Search API to collect images. After data cleanup, I ended up with 80 images of centipedes and 68 images of millipedes, split 80/20 for training and validation.

Machine learning model: I used the fastai vision library to build and train my model. Initially, I used ResNet34 as my pretrained model, but the resulting pickle file (file containing the trained model with weights) was too big for the app’s proper function. I downsized this file from 81 MB to 47 MB by going with ResNet18 instead.

After only ten epochs, the model achieved 93% accuracy.

Only two images were misclassified in the validation set (see confusion matrix above.

Making a Jupyter notebook widget: Using widgets, I created a simple prediction app following Jeremy’s book’s instructions (please see my GitHub repository for the notebook file).

The next step was to deploy a local app to the web. One of the easiest ways to do that is to use Binder. Binder allows running Jupyter notebooks in an executable environment on the web.

Source: https://mybinder.org/

You can upload your GitHub repository straight to the Binder website.
The GitHub repository must contain at least free files: Jupyter notebook with code, pickle file with your model and weights, and requirements.txt file to create your python environment. To bypass a 10 MB file upload limit on GitHub, you have to use Git Large File Storage (LFS) service. Git LFS replaces large files with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.

Source: https://mybinder.org/

To build and launch your GitHub repository, you provide your repository name or URL and Jupyter notebook file name. If you want your app to execute without displaying the code, you can use voila by putting “/voila/render/” before the Jupyter notebook file name. Voila turns Jupyter notebooks into standalone web applications. It is crucial to change the dropdown menu from file to URL to be able to access the app on the internet. Don’t forget to copy the Binder URL for your app to share it with your friends. After that, you press the “Launch” button and wait.

Unfortunately, since Binder has to build your environment, it may take up to ten minutes to launch your site. If the site is frequently used, the loading time is much shorter. The final version of my site looks like this:

Conclusion: a combination of fastai, voila, and Binder enables creative individuals to code and deploy simple web applications with not much effort. The good is that Binder is easy and free to use. Not so good is that it takes a long time to launch your application on Binder. The fact that Binder cannot handle substantial file sizes (I could not load 81 MB pickle file) is also a significant negative. The best is that my wife was thrilled with this app and that what counts the most for me.

Thank you for your time in reading this post.

Best wishes in these difficult times,

Andrew
@tampapath

Pathologist and Deep Learning Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store