Skip to content

SayedMaheen/SmogDetection

Repository files navigation

SmogDetection

Secure and Private AI challenge (SPAIC) Course

#sg_planetearth Group Project Project members:
Berenice Terwey - @Berenice
Shudipto Trafder - @Shudipto Trafder
Pooja Vinod - @Pooja Vinod
Ingus Terbets - @Ingus Terbets
Akash Antony - @Akash Antony
Ramkrishna Acharya - @Viper
Agata Gruza - @Agata [OR, USA]
Sayed Maheen Basheer - @Sayed Maheen Basheer
Abhishek Lalwani - @Abhishek Lalwani
George Christopoulos - @George Christopoulos
Sourav Kumar - @sourav kumar
Alexander Villasoto - @Alexander Villasoto
Laura Truncellito - @LauraT

Project Overview

This is a project for the Project Showcase Challenge of the Udacity Facebook Secure and Private AI Challenge Scholarship Program.

The purpose of the project is to detect smog using image classifcation algorithms. You can upload images here and our algorithms will know if the environment has smog or clear: https://smog4000.onrender.com/

Smog Detection Project


A project by #sg_planetearth (Facebook Secure and Private AI Scholarship Challenge 2019)


PART 1: PROJECT SUMMARY-


Description:
Smog Detection project has been created as a collaborative team effort between Facebook Secure and Private AI Scholars on #sg_planetearth. Main focus of the project is to provide Deep Learning solutions to solve most concerning real world problems, such as Climate Change, Food Security, Plastic Pollution, Deep Fake, Oceanic Pollution, Industrial Nuclear Waste, Clean Energy and more(using AI for social good). Currently our team is focusing on Smog and Fog detection on highways.

Why is it important? Why should we care?
Sudden appearance of smog and/or fog on the highway more often than not cause serious and sometimes fatal accidents. Smog is a main agent for severe air pollution. It can aggravate health problems including problems with breathing and sleeping, as well as it can inversely damage plants and forest cover.

Solution:
Monitoring, early smog detection and preventive action. By using traffic cameras and train a model to recognize the smog/fog patterns, we can automate the alert and send notification in a timely manner. When smog/fog appears, the system notifies drivers who are within specified range about an upcoming “obstacle”.

In any practical situation, there are other components that need to be taken into consideration as well. For example, presence of flying birds and any type of material that will block camera view. To identify the range of vision sensors need to be added to the solution.

Our approach:
There are plenty of existing solutions and advancements in computer vision. Our approach is to use Machine Learning Image Detection and train a CNN model. Smog Detection is a smog classification project, where images are arranged into two main cathegories: "Smog/Fog/NotClearlyVisible Highways" and "Clearly Visible Highways".

Project objective:
Smog is a byproduct of the global climate change scenario. As we move further into the industrialized age, Smog continues to pollute our air, reduce visibility on roads and is a leading cause of accidents on roads. The primary goal of the project is to avoid and help reduce rate of accidents in self driving vehicles by using this classifier model as one of the key components attached on traffic cams, so that the vehicle can automatically be alerted about smog on the roads/streets (highways) be it in heavy, medium or low traffic in order to adjust it's dynamics like speed, steering rotation, lanes etc. We can use the prediction output labels from the model to alert the vehicle / driver.

Dataset:
Since inception, people in the group have taken their task most seriously. They contributed towards building unique dataset which now has more than 4,000 images divided evenly between above-mentioned two groups. Our collection consists of:

DataSet1 DataSet2

Rules and regulations for selecting picture:

  • Only Highway(street)
  • Avoid large quantity of people
  • Avoid accident
  • Avoid Night Picture
  • Avoid bird eye view
  • Avoid large copyright watermark picture
  • Acceptable image format jpg, jpeg, png, jfif, webp

If in doubt about synthetic picture we were using https://people.ee.ethz.ch/~csakarid/SFSU_synthetic/
To detect and remove duplicates (regardless of format and resolution), we were using https://dupeguru.voltaicideas.net/ It's a nice and simple an Open Source tool that will work cross different platforms (Linux, OS X, Windows).

You can download our dataset here: https://drive.google.com/file/d/1ifKDpuF3zvEvsuBfZ4ZogSqWKZSxllKK/view?usp=sharing

Contributors:

  1. @Shudipto Trafder
  2. @Berenice
  3. @Agata [OR, USA]
  4. @Ingus Terbets
  5. @Akash Antony
  6. @Alexander Villasoto
  7. @Pooja Vinod
  8. @Viper
  9. @sourav kumar
  10. @George Christopoulos
  11. @Sayed Maheen Basheer
  12. @Abhishek Lalwani
  13. @LauraT

UPDATES:

Date Contribution
08/05/19 13th batch of images uploaded (20 for Clear and 20 for Smog folder)
08/04/19 12th batch of images uploaded (20 for Clear and 20 for Smog folder)
08/03/19 11th batch of images uploaded (20 for Clear and 20 for Smog folder)
08/02/19 10th batch of images uploaded (20 for Clear and 20 for Smog folder)
08/01/19 9th batch of images uploaded (20 for Clear and 20 for Smog folder)
07/31/19 8th batch of images uploaded (20 for Clear and 20 for Smog folder)
07/30/19 7th batch of images uploaded (20 for Clear and 20 for Smog folder)
07/29/19 6th batch of images uploaded (20 for Clear and 20 for Smog folder)
07/28/19 5th batch of images uploaded (20 for Clear and 20 for Smog folder)
07/27/19 4th batch of images uploaded (20 for Clear and 20 for Smog folder)
07/26/19 3rd batch of images uploaded (20 for Clear and 20 for Smog folder)
07/25/19 2nd batch of images uploaded (20 for Clear and 20 for Smog folder)
07/24/19 1st batch of images uploaded (20 for Clear and 20 for Smog folder)

More info:
https://github.com/SayedMaheen/SmogDetection
https://github.com/SayedMaheen/PlanetEarth
https://github.com/ingus-t/SmogDetection
https://github.com/ingus-t/SmogDetectionCombined
https://github.com/SayedMaheen/sg_PlanetEarth


Check out this exclusive web-app we have deployed for our project at https://smog4000.onrender.com/. At this site, you can upload your Smog/Clear images and test the accuracy of our classification system.

Screenshots from the User Interface:

'Smog' Detection

SmogDetectedImage


'Clear' Detection

RoadIsClearImage

While the application works for all images, it works best for highway images.


PART 2: TECHNICAL SUMMARY OF FINAL IMPLEMENTATION WITH PYTORCH-


This is a descriptive summary of Model Architecture we have implemented, and the Data Augmentations we have applied.

Input to model :

Images captured by traffic cam.

Output from model :

Prediction as label '0'(clear view) or '1'(smog detected).

Data Augmentations and Transformations

Model name

Description of model

So, there are five modules which contain deeper sublayers. Let's go through them one by one:

  • CNN layers : 7
  • Linear layers : 2
  • Pooling layers : 4
  • Batch normalization layers : 7

conv1 :

  • CNN layers : Conv2d(3, 32, 3, padding=1), Conv2d(32, 32, 3, stride=2, padding=1)
  • Pooling layer : MaxPool2d(2, 2)
  • Batch normalization layer : BatchNorm2d(32), nn.BatchNorm2d(32),

conv2 :

  • CNN layers : Conv2d(32, 64, 3, padding=1), Conv2d(64, 64, 3, stride=2, padding=1)
  • Pooling layer : MaxPool2d(2, 2)
  • Batch normalization layer : BatchNorm2d(32), nn.BatchNorm2d(64),

conv3 :

  • CNN layers : Conv2d(64, 128, 3, padding=1), Conv2d(128, 128, 3, stride=2, padding=1)
  • Pooling layer : MaxPool2d(2, 2)
  • Batch normalization layer : BatchNorm2d(128), BatchNorm2d(128)

conv4 :

  • CNN layers : Conv2d(128, 256, 3, padding=1)
  • Pooling layer : MaxPool2d(2, 2)
  • Batch normalization layer : BatchNorm2d(256)

fc :

  • Linear layers : Linear(256, 128), Linear(128, 2)

Dropout has been applied in conv4 and linear layer where probability = 0.35 in conv4 and 0.5 in fc.

Activation functions :

mila activation has been used. Activation Mila (@Diganta's new activation) https://github.com/digantamisra98/Mila

Optimizer :

Adam optimizer is used here.

Loss function :

CrossEntropyLoss is used.

Learning rate (with lr scheduler) :

  • lr schedular = StepLR(optimizer, step_size=10, gamma=0.5)
  • lr = 0.001

Epochs :

epoch : 50


RESULTS


Test loss :

Test Loss:36.734721

Test Accuracy :

Accuracy: 99.0000

Class wise loss :

  • Test Accuracy of 0: 98% (389/393)
  • Test Accuracy of 1: 98% (378/382)

Overall testing accuracy :

Test Accuracy (Overall): 98% (767/775)


Find the notebook for this implementation here


PART 3: TECHNICAL SUMMARY OF IMPLEMENTATION WITH KERAS:


Description

  • Libraries used: keras 2.2.4, numpy, matplotlib etc
  • Trained: On google Colab
  • Dataset Used: Smog4000

About dataset:

Smog4000 dataset created by our team.

Preprocessing of data

  • Rescale range: 1./255
  • shear and zoom: 0.2
  • color: RGB
  • Outshape: 224 X 224

About the model

Custom CNN model is used here. Complete summary of model architecture is given below:
The Sequential model have 3 blocks of CNN layers and one final linear layer. In each CNN block we have:

  • Convolution layers of same out filters(32, 32, 64, 64, 128, 128)
  • Filter shape: (3, 3)
  • Activation Function: relu(Rectified Linear Unit)
  • MaxPooling: pool size(3, 3)
  • BatchNormalization
  • Dropout: 0.25

The Final block is for linear layers. It has:

  • Flatten

  • Dense of out 256 and relu

  • BatchNormalization

  • Dropout of 0.5

  • Classification layer with sigmoid

  • Total parameters: 1,469,346

Model Compilation

  • Optimizer: Adam(Adaptive Momentum) Optimizer is used on this model.
  • Learning rate: default(0.001)
  • Loss function: Categorical_crossentropy (categories: clear, smog)

Training

  • Epochs: 10
  • Batch Size: 32

Performance

  • Train Accuracy: 0.9968
  • Validation Accuracy: 0.9921
  • Test Accuracy: 0.985
  • Train time: 750s per epochs

Future Implementations:

  • Usage of less parameters
  • Test with different optimizer and loss functions

Find the notebook for this implementation here.