How To Build A Waste Classifier App Using AI?
I’m training a convolutional neural network to classify an image as cardboard, glass, metal, paper, plastic, or trash with the fastai library. If you’re following along, download their dataset here and then move it to the same directory as the notebook.
Waste classifier app
Extract data
First, we need to extract the contents of dataset-resized.zip. Once unzipped, the dataset-resized folder has six subfolders.
Organize images into different folders
Now that we’ve extracted the data, I split the images into train, validation, and test folders split. I create a bunch of target folders following the ImageNet directory convention. This means it will have an outer folder with three subfolders: train, validation and test. Within each of these folders is a folder called Cardboard, Glass, Metal, Paper, Plastic, and Waste.
Model training
A pretrained CNN will perform better in new image classification tasks because it has already learned some visual features and can transfer that knowledge. Because they are able to describe more complexity, deep neural networks should theoretically perform better than shallow networks on the training data.
Finding a learning rate
I find the learning rate for gradient descent to make sure my neural network converges reasonably fast without missing an optimal error.
Make new predictions on test data
To see how this mode actually works, we need to make predictions on test data. First, I make predictions on the test data using the learner. The ds_type argument in get_preds takes the DataSet argument.
Next steps
If I had more time I would go back and reduce the classification error especially for the glass. I would also delete photos from the dataset that are overexposed because those images are just bad data. It’s pretty amazing how quickly you can build a state-of-the-art model using the fastai library.
Conclusion
We have successfully created a classifier that can distinguish between images of organic waste and images of recyclable waste. Combine the dataset used here with other waste classification datasets to increase accuracy and or number of waste classes classified experiment with other transfer learning models.