Deep Learning Series | Episode 2 | End-to-end Personal Project

Learn about step by step building my first end-to-end personal project for deep learning.

To practice what I learned in the second chapter of the book, I trained a tree classifier model and deployed it as a web application using Voila. The tree classifier is similar to the bear classifier project from the second chapter. 

I wanted to define a general process for my deep learning/machine learning projects. By reading this chapter of the book and a few more articles on the Internet, here is the general process I found out: 

  1. Problem definition: Look for a problem around you or an existing problem which can be solved by deep learning. For the beginning, it is recommended to use deep learning in the problem domains which we already know that it works (e.g. Image classification) 
  1. Gathering data: Finding the relevant data for the specific problem. Gathering data comes after defining a problem. So, better not to look for a problem to solve for existing data! Sometimes, we do not need massive amounts of data to train a good model as you might have already learned in this course.  
  1. Preparing the data: Preparing the data is supposed to take the most amount of time. This is where your programming skills could shine. This step can include data cleaning, data resizing, data augmentation and segmenting the data into training and validation sets.  
  1. Training and testing a model: The actual training of a model based on our training dataset and testing how the model performs on validation dataset. These jargons can be named differently by different people, frameworks, instructors.  
  1. Deploying the model: Once the model is performing as expected, it can be deployed on a cloud or a service like Binder as a web app or API app. Other people and organizations can use your model for inferencing on their own data.  

Tree Classifier Project 

Problem definition 

Recently, I was reading a book about scientific discoveries in the world of trees called “The Hidden Life of Trees”. Throughout the book, there are references to two types of trees, coniferous and deciduous. While walking outdoors, I wish I had a guide to identify types of trees for me. Even though such an app probably exists and by the end of the book I somehow learned how to distinguish between the two types, this became my simple problem. Given an image of a tree, the model/app should tell me what type of tree it is.  

Gathering data 

I downloaded images of my target tree types from the Internet using the same functions introduced in the book and the course website. If you do not have access to Bing Search API, or just prefer an easier function, use the DuckDuckGo function. I ended up using the images from both Bing Search API and DuckDuckGo. By default, the Bing function downloads 150 images for each search keyword. In addition, I set DuckDuckGo function to download 100 images for each category. As a result, I gathered 250 images for each category. In my case, the keywords are ‘coniferous tree’ and deciduous tree.’ 

Preparing the data 

I followed the same code provided in the book to create the parent directories for each category of trees. Used verify_images() function to make sure each image file can be opened.  

Then I spent enough time to get familiar with DataLoaders class from fastai. I recommend checking out the documentation for this class and trying to play around a bit with different examples. There is a fastai notebook tutorial for DataBlock which you can practice with different data types.  

Moreover, it is also important to learn about data augmentation and how it can affect your model performance. I went back and forth and changed different configurations and trained the model to see how it affects the model performance. This was a bit test and trial, but I hope to learn more intuition over time.  

Training and testing a model 

Training the model was trivial if you just follow the book. I tried different number of epochs to see how it affects the model performance. Sometimes, you notice there is a notable change in the next epoch and sometimes the difference is negligible. I really like the idea of plotting the confusion matrix which shows how many items were labeled correctly and how many were labeled incorrectly. Combined with ImageClassifierCleaner() function, I cleaned the data which was misleading or wrong to improve the performance further. The model achieved a 95% accuracy in 6 epochs in the end.  

Deploying the model 

I wanted to learn about Binder and Voila in this course, so again I followed the instructions in the book to deploy the model as a web application. I think Voila and Binder are really a quick and easy way to deploy a model for the public.  

For future deployments, I will try to use cloud deployments (e.g. Azure or Google Cloud).  

Conclusions 

It is a crucial part of learning to do own projects. The tree classifier project was easy enough for me to handle and gave me good hands-on experience and the opportunity to train a state-of-the-art deep learning model. I learned about different stages of a project and how to troubleshoot problems. I will continue with more complex projects to deepen my knowledge.