Learn practical skills, build real-world projects, and advance your career

Garbage Classification using PyTorch

Humans produce tons of garbage. This garbage, as we know needs to be segregated before it is taken out of our houses, as essential as this process is for the functioning of communities and sustaining of the mother earth, it is Tedious!

We all have, at some point imagined of having a robot personal assistant who will do all the chores for us, including garbage segregation. I mean, whom are we kidding? We hate to spend minutes staring at 6 garbage bins with a soda can in our hand and wondering where it goes. The dream is not a far fetched thought, but a reality thanks to progress in deep learning.

Today we will be building one such image classification model using PyTorch. PyTorch is a Python library with a wide variety of functions and operations, mostly used for deep learning. We will train this model by using a kaggle dataset of 2527 images belonging to 6 different garbage bins.
These being -

  1. cardboard
  2. glass
  3. metal
  4. paper
  5. plastic
  6. trash.
    The dataset is obtained from kaggle. (https://www.kaggle.com/asdasdasasdas/garbage-classification)

We will use the opendatasets library to download the dataset.

!pip install opendatasets --upgrade --quiet
import opendatasets as od

While downloading the dataset, you will be asked to provide your Kaggle username and credentails, which you can obtain using the "Create New API Token" button on your account page on Kaggle. Upload the kaggle.json notebook using the files tab or enter the username and key manually when prompted.

od.download('https://www.kaggle.com/asdasdasasdas/garbage-classification')
Please provide your Kaggle credentials to download this dataset. Learn more: http://bit.ly/kaggle-creds Your Kaggle username: adityapatkar Your Kaggle Key: ··········
11%|█ | 9.00M/82.0M [00:00<00:01, 54.8MB/s]
Downloading garbage-classification.zip to ./garbage-classification
100%|██████████| 82.0M/82.0M [00:00<00:00, 236MB/s]