Speech M1
Speech M1
Hello everyone! In this video, we will be exploring the code for a Garbage Classification
Preprocessing module. This module is a crucial step in our garbage classification project, where
we aim to classify garbage images into six different classes: 'Cardboard,' 'Glass,' 'Metal,'
'Paper,' 'Plastic,' and 'Trash.' The ultimate goal is to estimate pollution levels based on smoke
intensity in these images. Let's dive right in and understand how this preprocessing module
prepares the dataset for garbage classification.
[Code Overview]
The code is written in Python and uses libraries like PIL (Python Imaging Library), pathlib, os,
numpy, matplotlib, and torchvision. It assumes you are running it on Google Colab and mounts
Google Drive to access the dataset. The dataset is then unzipped and loaded into the
'/content/Garbage/original_images' directory.
Let's start by visualizing the class distribution of the dataset. We use matplotlib to plot a bar
chart, where each bar represents a garbage class, and its height corresponds to the number of
images in that class. This visualization helps us understand the distribution of data across
different classes like 'Cardboard,' 'Glass,' 'Metal,' 'Paper,' 'Plastic,' and 'Trash.'
```
[Image Preprocessing]
Next, we perform image preprocessing to ensure all images are in a consistent format before
feeding them into the classification model. We define the function 'convert_scale' to handle
image preprocessing tasks for each class. It resizes the images to a uniform size of 32x32
pixels and converts them to grayscale. The processed grayscale images are then saved to the
'/content/Garbage/processed_images' directory. This preprocessing step ensures consistency in
input sizes and simplifies feature representations.
Now, let's inspect a sample of 5 images from each class in the original dataset. We have a
custom function, 'get_image_paths,' that retrieves image file paths from a given folder path. The
'plot_sample_images' function then visualizes these sample images in a single row for each
class using matplotlib. This allows us to gain insights into the quality and variety of data
available for training or testing our classification model.
[Sample Image Visualization - Processed Dataset]
Next, we repeat the same process of inspecting a sample of 5 images, but this time from the
processed dataset. We use the images that have been resized and converted to grayscale, so
we can observe the changes that occurred during the preprocessing step.
[Conclusion]
Stay tuned for our next video, where we will explore the garbage classification model using the
Sequential architecture. Thank you for watching, and don't forget to subscribe to our channel for
more exciting updates on this project!