Image Weather Classification

CNN based weather classifier

Convolutional Neural Network also known as CNN are of grate use when it comes to image data. They can be used to get both low level features and high level features. CNN are used in many places now and is future of robotics.
uses of CNN
  • Robotic Vision
  • Biometric identification
  • object detection and tracking
  • Self Driving Car
  • Object Identification

We are going to classify weather images using Convolutional Neural Network. 



This task can be performed in multiple ways and we are going to classify weather using regression network. The Network I have created is given below.


python libraries required
  • numpy
  • os
  • glob
  • OpenCV
  • Tensorflow keras
  • Pands
  • Matplotlib
For weather classification problem download the dataset from link(link)
 

Dataset description

  • number of images 1025
  • size of images variable
  • labels are mentioned in the name of images
  • number of labels 4 ['cloudy' , 'rain', 'shine', 'sunrise']
Create a file labelgenerator.py to generate labels from images. Give path name to the images directory now create a loop and read all the file names. File name is string so check if 'label' is in filename and provide number to the label and save them in file named label.npz
cloud 0, rain 1, shine 2, sunrise 3


 
Create your training file and import cv2, numpy, os, glob, matplotlib, Tensorflow Keras as given below
Now read images from directory then reshape them to [100, 100] shape RGB image. Store all images in a variable Data. Reshape helps in controlling the size of image so that network input size can be fixed.
Read the labels and then use train_test split function to split data for 80:20 ratio in training and testing.




Create a sequential model and add Conv2d layer to it. Variables in a conv2d layer are
  • Number of filters
  • Kernel Size
  • Activation Function
All three of them can be varied but in our case we will fix the number of filters and kernel size. I have tested multiple activation functions like
  • Sigmoid
  • Relu
  • Tanh
Selection of any activation function affects learning rate and accuracy a comparison of accuracy between them is given below.

                                    

We add 4 Conv2d layers with activation function as tanh and kernel size (3, 3)
number of filters for first layer 32 and for rest 3 it is 30. Flatten the network and add dense layer of size 20 with activation relu then dense layer of size 15 and finally output layer having single node and activation function Linear. In Output layer there are many activation functions available but for regression linear activation function is preferred
Train network at 15 epoch and batch size of 50. Check accuracy on test dataset, after this save the weights and now you can use it to predict new images.

We can see Accuracy increases as the number of epochs increases. and Loss keeps on decreasing.
                            


Some of The Predicted images are given below




GitHub link of the full code is given below

 
     

Comments

Popular posts from this blog

Background Subtraction OpenCv Python

Opencv python object detection Tutorial (part 1)