Weather classification
- vrk6637
- Dec 7, 2021
- 5 min read
Why weather classification?
The weather conditions not only strongly influence us in our daily lives through the solar energy system and outdoor sporting events as examples, but also affects the functionality of many visual systems including outdoor video surveillance and vehicle assistant driving systems (by heavy rain, haze, etc.). It is no doubt that, judging the weather conditions by a single image, also known as weather classification task, plays a vital role in many visual and weather systems.
Nowadays, the weather classification task is commonly accomplished by the human vision or expensive sensors. Since weather condition is local to an area, lack of the required human resources and/or the expensive sensors limits the availability of local measurement of the weather condition.
Recently, researchers argued that computer vision techniques could be developed to accurately classify weather conditions through images, which might save expensive human and instrumental resources (i.e., sensors) since economical surveillance cameras are ubiquitous and would be sufficient to accomplish weather classification.
In this article we are going to build the application which is going to classify the image whether it is cloudy, rainy or sunrise or shine. We are going to discuss more about our classifier model.
This is the link where are getting our data set from.

These are the required libraries to train and validate our model.

We are resizing the images 180*180 pixels and creating each batch with 32 images.
Resizing images is the main step, machine learning models train faster on smaller images. An input image that is twice as large requires our network to learn from four times as many pixels — and that time adds up. Moreover, many deep learning model architectures require that our images are the same size, and our raw collected images may vary in size.

From the given data set, we are splitting it as 80% trained data set and 20% test data set.
IN total we have 1125 images, so 900 files will come under training set and remaining comes under validation dataset.
1. Training set: contains the data that we use for the training being our training dataset
2. Testing set: contains the subset of data for testing. We use this test data set to find the accuracy of the model

To train multi-class weather classifier, we need to do the following steps:
1.Load and normalize the dataset
2.Define a Convolutional Neural Network
3.Define a loss function
4.Train the network on the training data
5.Test the network on the test data
Load and normalize the data:
we are using keras libraries to load and normalize data.
For most image data, the pixel values are integers with values between 0 and 255. Neural networks process inputs using small weight values, and inputs with large integer values can disrupt or slow down the learning process. As such it is good practice to normalize the pixel values so that each pixel value has a value between 0 and 1.

Class names:
class_names
['cloudy', 'rain', 'shine', 'sunrise']
Creating a convolution neural network model:

what is CNN?
CNN is a Deep Learning algorithm which can take in an input image, assign importance (learnable weights and biases) to various aspects/objects in the image and be able to differentiate one from the other.
What is RELU?
The rectified linear activation function or RELU for short is a piecewise linear function that will output the input directly if it is positive, otherwise, it will output zero. It has become the default activation function for many types of neural networks because a model that uses it is easier to train and often achieves better performance.
what is max pooling in CNN?
Max pooling is a pooling operation that selects the maximum element from the region of the feature map covered by the filter. Thus, the output after max-pooling layer would be a feature map containing the most prominent features of the previous feature map.
we have used Keras library for implementing this model. I have implemented 2 models experimenting with different hyperparameters for the weather classification
Convolution Model 1:
1. Three convolution layers with 1 fully connected dense layer at the end
2. 1 convolution layer with 16 filters each with 3*3 kernel size with activation function as RELU which is further connected with the max pool layer.
3. Next convolution layer with 32 filters each with 3*3 kernel size with relu activation which is further connected with the max pool layer
4. The final layer is with 64 filters with 3*3 kernel size with relu activation and which is connected with the max pool layer.
5. And then we have flattened the layer that we have built till now and then it is connected to a dense layer with 128 neurons. Connected to 4 classes.
6. Then we have used Adam optimizer adaptive gradient descent algorithm for minimizing the cross-entropy loss for improving the accuracy of the model.
7. Epoch size we used I this model is 10 with batch size of 32 .
8. After all the execution, the average accuracy of the model is: 89.7 %’


Graphs for training and validation accuracy and Training and validation loss

Convolution model 2:
The main change we have made this model is drop out layer to improve more accuracy of the model. we have added drop out parameter 10%,20%,20% between the convolution layers and kept the epoch as 10 with batch size 29 and finding the accuracy of the model.

Graphs for training and validation accuracy and Training and validation loss for model 2

The accuracy we got for the validation set on this model is 86.6% which is less than the first model. Which means that the model is not overfitted and adding dropout layers to the model is not improving the accuracy of the model.

My Contribution
I have developed this algorithm from scratch using Convolutional neural networks by trail and error methodology
I have researched below mentioned references in the blog page
and able to 2 Convolution Neural Network models with different hyper parameter's
Experimented number of neurons per layer
Experimented with number of layers
Experimented epoch values
Experimented with shape of conv2d .
Made use of drop out layer, however model was not overfitted. so, adding dropout layer did not increase any accuracy of the model.
Challenges Faced and Solution for them
Finding the right parameters to increase the accuracy of the model was challenging.
I managed to high accuracy by experimenting the above mentioned parameters in the My contribution section.
Algorithms Used
I have used CNN algorithm for implementing the image classification it an efficient recognition algorithm which is widely used in pattern recognition and image processing. It has many features such as simple structure, less training parameters and adaptability.
A convolutional neural network has the following layers:
Input Layer - This is the layer where the input image size to the model is specified.
Convolutional layer - This layer has filters with kernels of specified size, the kernel is initialized with the random values from the standard normal distributi0n. and dot multiplied with the image input. with small step called stride after each dot multiplication operation. Typically, Stride is 1.
Activation layer - which gives output when the layer values is greater than a threshold.
Pooling layer - this layer votes the highest values in the window size specified from the previous layers output. and sends to the next convolutional layer (0r) Dense Layer (Fully Connected Layer). This can be RELU, Sigmoid, Tanh, Leaky RELU.
Dense(Fully Connected Layer) - At this layer the 2d volume of output obtained from the pervious convolutional layer is flattened to 1d and connected to the specified number of dense layer.
Final Dense Layer - This is the same layer as the Fully connected layer, Here we specify the number of nodes that will the the number of classes that we are classifying the images into.
Evaluation Score
The accuracy we got for this model is 89.7%
Documents Links:
Notebook File : https://github.com/kishorereddy701498/DataMining_MainProject/blob/main/Main_Project.ipynb
Data Set Link : https://www.kaggle.com/kishorereddy94/dataset
Project Proposal : https://github.com/kishorereddy701498/DataMining_MainProject/blob/main/Weather%20Classification%20Proposal.docx
Project Sketches :
Read Me File :
Video Demo Link : https://youtu.be/U8c72wce9ok
References :



Comments