Convolutional network based Classification

CNN based weather classifier

CNN(convolutional neural network) are very powerful Computation Weapon made by multiple mathematical processes. CNN can be used by robots to see environment through camera and understand the state of environment. A single layer of CNN works as a filter much like gaussian blur or edge detector filters and when they are used in multiple layers they can understand much  more than just color or shape, they can understand story of the image and today we are going to learn how to train a CNN to predict weather through image.

Weather-CNN


Before we start make sure you have tensorflow,keras,OpenCV, Matplotlib and pandas. we have to download dataset for wether images. Link to image dataset link(https://md-datasets-public-files-prod.s3.eu-west-1.amazonaws.com/64a54851-f95a-439d-aff7-3334a684e532)
dataset consist of 1025 images of weather, it consist of 4 labels 'cloudy','rain','shine','sunrise', image shape varies.




Import dataset, read image labels and save the file as lable.txt this is a part of preprocessing 






Create a new Training.py file and import libraries, all imports are given below.Now read images and labels.txt file and convert labels to hot vectors. Hot vectors works like n-arm bandit problem where we select 1 of all available actions. A hot vector looks like [0 1 0 0] for action  = 2, and are used in classification problems. Reshape images so that all images are of same shape in this case we have reshaped it to (100, 100).




Make sure to fix the random seed to get reproduceable results,make a sequential model with 4 convolutional 2d layers then flatten it and add 2 dense layers and 1 output layer. Full Network summery is given below.

we are using tanh activation function in 2d CNN layers as they produce better results than RELU and Sigmoid activation functions. Accuracy and loss funtion for all three are attached below with epoch and batch size fixed at epoch = 10 and batch size = 50. Plot of model loss and accuracy are given below.
 
Some of the results from prediction are given below, model can not predict right always but gives a fair result.
 
 
      






Comments

Popular posts from this blog

Background Subtraction OpenCv Python

Opencv python object detection Tutorial (part 1)