HypeTeq

How to optimize your CNN mode

CNN Mode

How to optimize your CNN mode

The technology has become so much advanced with the advancement of Artificial Intelligence automating tasks and solving issues making our life simpler and easier. For such advancement, it becomes necessary for our technology to understand the images and process them. That’s when CNN comes into the picture. CNN [ Convolutional Neural Network ] is a kind of artificial neural network used as an ideal solution for most computer vision and image analysis-related problems such as image recognition and image classification. For example, To explain CNN in simple terms the computer trains itself to identify and recognize the image the same way a parent teaches his small child to recognize objects. Before moving into how to optimize your model let’s understand the basic CNN architecture and its components.

CNN Architecture

A CNN network consists of three layers: A convolutional layer, a pooling layer, and a fully convoluted layer.
The major building elements are convolutional layers. The layers consist of input vectors such as images and filters. The input layer holds the input image. The input is convolved by convolutional layers which pass this to the next layer. Each neuron present in the convolutional layer processes the data. These convolutional layers filter the input data and extract the information from the image. The purpose of the pooling layer is to reduce the size of the volume which makes the computation fast reduces the memory and prevents overfitting. A pooling layer is inserted between the converts. There are two common types of pooling mostly used Max-pooling and Average pooling. In max-pooling, the maximum value from a given part of the image covered by the kernel is obtained. Average pooling returns the average value from the portion of the image covered by the kernel.
In the end, there is a fully connected layer of neurons. This layer takes the input of all the previous layers and computes the class score. After training the feature vector from the fully connected layer is used to classify images into different categories. It helps to map the representation between the input and the output.

How to optimize your CNN model?

Here I will be listing down a few techniques that will be helpful to increase the accuracy of a CNN model and will also help in reducing the overfitting of the model.
  • Data Normalization: It helps in preventing the pixel values from any one channel from disproportionately affecting the losses and gradients. 
  • Dropout: Overfitting one of the most common problems which is faced while training the model. In overfitting, the model works well on testing the given training data but when testing the new data the model fails. Adding dropout layers helps in eliminating the overfitting of data. A dropout layer is utilized wherein few neurons are dropped during the training process. 
  • Kernel/ Filter Size: The filter size depends on the number of pixels necessary in your network in simple words bigger filters represent more global, high-level representative information so if you want your model to focus on the overall image use large filters (as 11×11 or 9×9). And if you want to focus on minute details use small filters (3×3 or 5×5). 
  • Activation functions: It is the most important parameter in the model as it decides which information should be passed in to forward direction and which should not. There are several commonly used activation functions such as ReLU, Softmax, tanH, Sigmoid, etc. In the case of a binary classification CNN model, sigmoid and softmax functions are preferred, and in the case of a multi-class classification model, softmax is generally used. 
  • Optimizer: Choosing the right optimizer helps in optimizing the model. There are different optimizers used following the given input data such as gradient descent, stochastic gradient descent, Adagrad, Adadelta, RMSprop, Adam, etc. The most effective and commonly used optimizer is adam due to its effectiveness in adding bias correction and momentum compared to RMSprop as the gradients become sparser. 
  • Data Augmentation: When you have a very less amount of data, it becomes harder to train the model and achieve accuracy. In this case, data augmentation helps to increase the data. In data augmentation, we apply various kinds of transforms to our dataset at random
  • . Here we do a few transformations in our images such as a bit of rotation, zoom, translation, brightness, contrast, symmetric wrap [changing the angle], etc. 
  • Weight decay: We added weight decay to the optimizer, yet another regularization technique that prevents the weights from becoming too large by adding a term to the loss function. 
  • Batch normalization: After each convolutional layer we add a batch normalization layer which helps in normalizing the output of the previous layer. 
  • Tuning learning rate and epochs: The number of epochs affects the performance but we do certain experiments with it; we can see after certain epochs there is not any reduction in loss and training performance. Also experimenting with the learning rate following the input data help in improving the accuracy. 
  • Image size: While training the image size can also have a great impact as if the size is too small the model fails to pick up the important features and if too big then the model may take a longer time to process it. Common image sizes include 64×64, 128×128,and 224×224 (VGG-16). 
  • Using Transfer learning: It involves the use of pre-trained models such as Yolo, ResNet, etc. A pre-trained model is a state-of-the-art deep learning model that was trained on millions and millions of samples. These models can be used as a base of your model if you are unable to build an effective model or if your model fails to achieve good accuracy. 

Conclusion

Choosing the parameters from the above-given points depends on the type of dataset you are using and the type of problem you are solving such as object detection, classification, or segmentation. Apart from these, many parameters need to be considered which can help in optimizing the model.

Tagged:

SAY HELLO

Follow Us on Social Media

en_USEnglish