ACHIEVEMENTS

This post will be an over view some of the key achievements Ive counter. As show on the image above, Currently I’m now able to run clash detection purely on Revit and Dynamo to speed up the design…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Classifying Waste Images with Machine Learning

How AI can help us reduce, reuse, recycle

With the amount of waste produced daily worldwide, waste management is a massive problem. A significant part of this issue is waste classification. But what if we could use AI to automate the process?

Similar to my past article on Pokémon classification, I’ll do this using a convolutional neural network.

This is the dataset that I’ll be using:

It is split into test and train directories that are both further divided into organic and recyclable folders.

To prevent this, we’ll trim the organic data down to the size of the recyclable data. I did this within file explorer with the files sorted according to descending file size for randomness. Alternative solutions include:

You can read about more methods for dealing with imbalanced data here:

First things first, I import the python libraries that we’ll need throughout this project:

Then I set up the paths to each directory. If you’re using Google Colab, I recommend uploading the dataset as a zip file and extracting it within the notebook.

From the output, we have 9999 training and 1112 validation images for each class.

We’ll need to know what the shapes of the images are for our machine learning model, so let’s take a look at a few samples:

All images are RGB, but their dimensions vary, which needs to be accounted for when preprocessing the data. I’ve also displayed sample images from each class. The first four are from the organic directory, while the bottom four are recyclable.

To start, I’ll import the libraries we’ll need for preprocessing and building the machine learning models:

Now we’ll create our image data generators. We’ll rescale the data between 0 and 1 while resizing the images to be 150 by 150. From my trial runs, data augmentation did not improve model performance.

Now we’re ready to train our classifiers! I’ll be creating two machine learning models: a CNN from scratch and a transfer learning model. I based my models on this image classification practicum by Google Developers:

If you’re using Google Colab, I recommend using the GPU hardware accelerator to speed up the training process.

2. Transfer Learning Model

For my transfer learning model, I’ll make use of Google’s Inception v3 model. You can read more about Inception v3 here:

The CNN from scratch achieved slightly higher accuracy than the transfer learning model, so let’s visualize and evaluate its performance!

First, let’s test our classifier on the validation set:

Organic samples correspond to the label 0, while recyclable samples correspond to 1. Out of the 2224 validation images, our model misclassified 197.

To better visualize these results, let’s output the images of the classified waste along with correctness labels.

We can also evaluate our model’s performance using other metrics. Using evaluate():

Our model’s accuracy on the validation set is about 91%, while the loss is about 0.25.

Using the scikit-learn library, we can also create a confusion matrix and a classification report with more details:

From my previous article on sarcasm detection:

As for the classification report:

You can read more about these classification metrics here:

The same model performance evaluation can be done for our transfer learning model.

We’ve successfully built a classifier that can differentiate between images of organic waste and images of recyclable waste! But we still have a long way to go before solving the world’s waste crisis. Here are some ideas for taking this project further:

In addition to the ones linked throughout this article, I wouldn’t have been able to complete this project without the help of these awesome examples and tutorials:

Add a comment

Related posts:

What has become of us?

This is the second part in our photo essay series, A Shift in Culture. Part two features Aisha Thurman-Cosby, Director of District 2 Pre-K Center in New York City. Thurman-Cosby is a former classroom…

Being Queer in Quarantine

Since the beginning of March, I’ve been quarantining at my parent’s house in central Pennsylvania. All my potential life plans were put on hold and while this wasn’t in my five year plan I’m trying…

The Day I Started Making Peace with My Tragic Past

During the path of my life journey, the years between 1994 and 1999 have been put in a box hidden far away. I had promised myself not to ever touch it and keep it buried where it belonged: in the…