Team Ai
Apppublic

syariefsq/ComputerVisionRoadCleanlinessClassifier

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
eda.py143 linesDownload Raw Back to src
1 2# Streamlit EDA for Clean/Dirty Road Image Classification3import streamlit as st4import os5import numpy as np6import matplotlib.pyplot as plt7from PIL import Image8 9 10def run():11 12    st.title("🛣️ Road Cleanliness Image Classification - EDA")13    st.markdown("""14    In the EDA section, we’ll dive deep into the analysis of our initial datasets. We’ll use visualisation and statistics to find insights, solve problems, and identify potential challenges for modelling through Image Characteristic analysis.15    """)16 17    st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSBOtq0ZnBAUQscpWd7i-s4-knfps_J49QGvg&s", caption="Road Cleanliness Image Classification - EDA", use_container_width=True)18 19    st.header("1. About the Dataset")20    st.markdown("""21    - **Source:** Kaggle - Clean/Dirty Road Classification Dataset  22    - **Classes:** 2 (Clean, Dirty)  23    - **Images:** Each image is labeled as either a clean or dirty road.  24    """)25 26    st.header("2. Preview Images")27 28    image = Image.open('src/Preview Dirty Class.png')29    st.image(image, caption='Dirty Road Example')30 31    st.markdown("""32    As you can see, dirty roads in this dataset are characterized by visible piles of trash, scattered plastics, paper, bottles, and sometimes even large accumulations of waste. These visual cues are what the model will use to distinguish between clean and dirty roads.33    """)34 35    image = Image.open('src/Preview Clean Class.png')36    st.image(image, caption='Clean Road Example')37 38    st.markdown("""39    As you can see, clean roads in this dataset are characterized by well-maintained pavement, clear roadlines, and a lack of visible trash or debris. These visual cues are what the model will use to distinguish between clean and dirty roads.40    """)41 42 43    st.header("3. What Makes a Road Clean or Dirty?")44    st.markdown("""45    To begin, we will first define what are each classes means.46 47    > **Clean :** *we can define as the road that are free from significant litter, debris, or accumulated waste on the pavement, shoulder, or immediate roadside. The road surface appears relatively clear, and road markings (lines) are often visible. The focus is on the absence of visible trash or large amounts of debris.*48 49    > **Dirty :** *we can define as the presence of visible litter, trash, garbage bags, or accumulated waste on the road surface, shoulder, or immediate roadside. The term “dirty” refers to human-generated waste, not mud, water, or cracks in the pavement.*50 51 52 53    From that definition, then we can visually inspect there are differencet charactheristic for both classes as follows:54 55    **Clean**56 57    - Well maintained pavement58    - Clear roadlines59    - Clean road shoulder60    - Natural surrounding(sky,trees,landscapes)61    - Clean infrastrctures (building, road marking)62    - No trash visible63 64    **Dirty**65 66    - Scattered Trash (plastics, bottles, packagings)67    - Piles of garbages, mountain of garbages68    - Road debris and dirts on the roadside or spilling to the road69    - Poorly maintained infrastucture70    - Unpaved Road71    """)72 73 74 75    st.header("4. Class Distribution")76    st.markdown("The dataset is generally balanced between clean and dirty road images, which is good for training a model.")77    st.write("#### Class Distribution")78 79    image = Image.open('src/Distribution Class.png')80    st.image(image, caption='Distribution of Clean and Dirty Classes')81    st.markdown("""82    The class distribution is balanced, with approximately equal numbers of clean and dirty road images. This balance is beneficial for training a model, as it helps prevent bias towards one class over the other.83    """)84 85    st.header("5. Color Channel")86    st.markdown("""            87    After checked the cell above, and it confirms that our dataset images are loading in RGB format (3 color channels).88 89    This is important because color information is crucial for detecting and distinguishing objects like dirt, debris, or piles of garbage, which often have striking colors.90    """)91 92    st.header("6. Image Resizing")93    st.markdown("""            94    All images are resized to: 128x12895                96    Image Height: 12897                98    Image Width: 12899 100    Above we can see the original image sizes were varied between all the datasets and we unify the size of image to define as the target size.101 102    The target size after resizing is 128x128, it was done in the previous step using `ImageDataGenerator`, this is necessary steps to provide uniform input to the CNN model.103                104    """)105 106    st.header("7. Image Characteristics")107 108    image = Image.open('src/Image Charactheristic.png')109    st.image(image, caption='Image Characteristics')110 111    st.markdown("""112 113 114    **Observations on Image Characteristics:**115 116    1. **Typical Angles/Perspective:** Angles and prespective are vary including views looking straight down the road (often highways or rural areas), angled views from the side (common in urban or dirty scenes), and slightly elevated perspectives. Not consistent across all images.117 118 119    2. **Road Surface Types:** Primarily Ashpalt or concrete roads. Some images in the class `dirty` shows dirt road, unpaved and gravel roads.120 121 122    3. **Presence of Other Objects:** Other objects such as vehicle (Cars, buses, truck and motorcylce) are common. People doing activities can also be spotted across images. There are buildings, walls, trees and grass alongside the road. The most significant presence especially in class `dirty` notably large garbage bins, piles of garbages.123 124 125    4. **Lighting Conditions:** Vary across images due to different camera or capture qualities. However, we can see images in bright sunny conditions, overcast skies, cloudy skies, and overexposed pictures (midday light).126 127    5. **Dirtiness**: This charactheristic exclusive to the `dirty` class, as we can see on the images it is predominantly scattered litter such as plastic bags in form of piles in the side of the road. It is not a natural dirt but mostly rather a human generated trash.128 129    6. **Image Quality:** The images are mostly good, but some are a bit blurry or out of focus. However, we tried to unify them by setting the image size.130 131    """)132 133    st.header("8. EDA Insight")134    st.markdown("""            135    Based on our exploratory data analysis, the litter or garbage would be our primary focus, especially in the `class 1` or `dirty` category. We want the model to be able to detect this later on, not just the general condition of the road.136 137    There are also variations in the characteristics of both classes, such as the presence of other objects like humans, buildings, and background scenes.138 139    We definitely expect the model to be able to identify other patterns beyond our sample observations. There will likely be a new type of trash pattern that occurs throughout the dataset, and the small amount of images (dataset) will be a significant challenge in training the model.140    """)141 142if __name__ == "__main__":143    run()