Image Classification with CNN Techniques
Image Classification with CNN Techniques
net/publication/333191474
CITATIONS READS
64 4,206
2 authors, including:
SEE PROFILE
All content following this page was uploaded by Md. Anwar Hossain on 18 May 2019.
ClassificationofImageusingConvolutionalNeuralNetworkCNN
© 2019. Md. Anwar Hossain & Md. Shahriar Alam Sajib. This is a research/review paper, distributed under the terms of the
Creative Commons Attribution-Noncommercial 3.0 Unported License [Link] permitting
all non-commercial use, distribution, and reproduction in any medium, provided the original work is properly cited.
Classification of Image using Convolutional
Neural Network (CNN)
Md. Anwar Hossainα & Md. Shahriar Alam Sajibσ
Abstract- Computer vision is concerned with the automatic We use this dataset to train machine learning and
extraction, analysis, and understanding of useful information computer vision algorithms. CIFAR-10 database is the
from a single image or a sequence of images. We have used contribution of Alex Krizhevsky and Geoffrey Hinton. This
2 019
Convolutional Neural Networks (CNN) in automatic image
dataset has 60,000 colored images. It has ten classes,
classification systems. In most cases, we utilize the features
and they are an airplane, automobile, bird, cat, deer,
Year
from the top layer of the CNN for classification; however, those
features may not contain enough useful information to predict dog, frog, horse, ship, truck. The images are of size
an image correctly. In some cases, features from the lower 32x32 pixels. The dataset consists of 50,000 training 13
layer carry more discriminative power than those from the top. and 10,000 testing examples. It is a database for people
Therefore, applying features from a specific layer only to who want to try learning techniques and pattern
Global Journal of Computer Science and Technology ( D ) Volume XIX Issue II Version I
classification seems to be a process that does not utilize recognition methods on real-world data while spending
learned CNN’s potential discriminant power to its full extent. minimal efforts on preprocessing and formatting. We will
Because of this property we are in need of fusion of features use this database in our experiment.
from multiple layers. We want to create a model with multiple
layers that will be able to recognize and classify the images. b) Convolutional Neural Networks
We want to complete our model by using the concepts of Convolutional neural networks are deep artificial
Convolutional Neural Network and CIFAR-10 dataset. neural networks. We use CNN to classify images, cluster
Moreover, we will show how MatConvNet can be used to them by similarity (photo search), and perform object
implement our model with CPU training as well as less training
recognition within scenes. It can be used to identify
time. The objective of our work is to learn and practically apply
faces, individual, street signs, tumors, platypuses and
the concepts of Convolutional Neural Network.
Keywords: convolutional neural network, CIFAR-10 many other aspects of visual data. The convolutional
dataset, MatConvNet, relu, softmax. layer is the core building block of a CNN. The layer’s
parameters consist of a set of learnable filters (or
I. Introduction kernels) which have a small receptive field but extend
through the full depth of the input volume. During the
C
onvolutional Neural Networks (CNN) becomes forward pass, each filter is convolved across the width
one of the most appealing approaches recently and height of the input volume, computing the dot
and has been an ultimate factor in a variety of product, and producing a 2-dimensional activation map
recent success and challenging applications related to of that filter. As a result, the network learns about the
machine learning applications such as challenge filters. The filter activates when they see some specific
ImageNet object detection, image classification, and type of feature at some spatial position in the input.
face recognition. Therefore, we consider CNN as our Then the activation maps are fed into a downsampling
model for our challenging tasks of image classification. layer, and like convolutions, this method is applied one
We use CNN for segmentation and classification of the patch at a time. CNN has also fully connected layer that
images in academic and business transactions. We use classifies output with one label per node.
image recognition in different areas for example
automated image organization, stock photography, face II. Related Works
recognition, and many other related works.
Image recognition has an active community of
a) CIFAR-10 Database academics studying it. A lot of important work on
The CIFAR-10 database (Canadian Institute for convolutional neural networks happened for image
Advanced Research database) is a collection of images. recognition [1,2,3,4]. The most dominant recent works
achieved using CNN is a challenging work introduced
Author α: Assistant Professor, Department of Information &
by Alex Krizhevsky [5], who used CNN for challenge
Communication Engineering, Faculty of Engineering & Technology, classification ImageNet. Active areas of research are:
Pabna University of Science & Technology, Pabna, Bangladesh. object detection [14,15,16], scene labeling [17],
e-mail: [Link]@[Link] segmentation [18,19], face recognition, and variety of
Author σ: Student, Department of Information & Communication
Engineering, Faculty of Engineering & Technology, Pabna University of
other tasks [20,21,22].
Science & Technology, Pabna, Bangladesh.
e-mail: sajibpust130639@[Link]
III. Methodology
Deep Learning has emerged as a main tool for
self-perception problems like understanding images, the
voice from humans, robots exploring the world. We aim
to implement the concept of the Convolutional Neural
Network for the recognition of images. Understanding
CNN and applying it to the image recognition system is
Fig. 1: Convolution Operation
the target of the proposed model. Convolutional Neural
Network extracts the feature maps from the 2D images When constructing CNN, it is common to insert
by using filters. The Convolutional neural network pooling layers after each convolution layer, so that we
considers the mapping of image pixels with the can reduce the spatial size of the representation. This
2 019
neighborhood space rather than having a fully layer reduces the parameter counts, and thus reduces
connected layer of neurons. The Convolutional neural the computational complexity. Also, pooling layers help
Year
network has been proved to be a very dominant and with the overfitting problem. We select a pooling size to
potential tool in image processing. Even in the fields of reduce the amount of the parameters by selecting the
14
computer vision such as handwriting recognition, natural maximum, average, or sum values inside these pixels.
object classification, and segmentation, CNN has Fig.2 shows the max pooling and average pooling
Global Journal of Computer Science and Technology ( D ) Volume XIX Issue II Version I
2 019
Fig. 4: The architecture of our proposed CNN
Year
b) Explanation of the Model Layer-4 is the average pooling layer. This layer
A simple convolutional network is a sequence of gets the input of size 32@10*10 from the previous layer.
15
layers. The layer transforms one volume of activations to The pooling size is 2*2; padding is 0 and stride is 2.
another through a differentiable function. We use three After this max pooling operation, we get a feature map
Global Journal of Computer Science and Technology ( D ) Volume XIX Issue II Version I
main types of layers to build network architecture. They of size 32@5*5.
are a convolutional layer, pooling layer, and fully Layer-5 is the third convolutional layer with ReLu
connected layer. We will stack these layers to form six activation function. This layer gets the input of size
layers of network architecture. We will go into more 32@5*5 from the previous layer. The filter size is 4*4;
details below. padding is 0, the stride is 1, and the number of filters is
Fig.4 shows the architecture of our proposed 64. After this convolution operation, we get feature maps
CNN model. At first, we need some pre-processing on of size 64@1*1. This layer acts as a fully connected
the images like resizing images, normalizing the pixel layer and produces a one-dimensional vector of size 64
values, etc. After the necessary pre-processing, data is by being flattened.
ready to be fed into the model. Layer-6 is the last layer of the network. It is a
Layer-1 consists of the convolutional layer with fully connected layer. This layer will compute the class
ReLu (Rectified Linear Unit) activation function which is scores, resulting in a vector of size 10, where each of
the first convolutional layer of our CNN architecture. This the ten numbers corresponds to a class score, such as
layer gets the pre-processed image as the input of size among the ten categories of CIFAR-10 dataset. For final
n*n=32*32. The convolutional filter size (f*f) is 5*5, outputs, we use the softmax activation function.
padding (p) is 0(around all the sides of the image), In this way, CNN transforms the original image
stride (s) is 1, and the number of filters is 32. After this layer by layer from the main pixel values to the final
convolution operation, we get feature maps of size class scores. Note that some layers contain parameters,
32@28*28 where 32 is the number of feature maps and others don’t. In particular, the convolution/fully
which is equal to the number of filters used, and 28 connected layers perform transformations that are a
comes from the formula ((n+2p-f)/s) +1= ((32+2*0- function of not only the activations in the input volume
5)/1) +1=28. Then the ReLu activation is done in each but also of the parameters (the weights and biases of
feature map. the neurons). On the other hand, the Relu/pooling layers
Layer-2 is the max pooling layer. This layer gets will implement a fixed function. We train the parameters
the input of size 32@28*28 from the previous layer. The in the convolutional/fully connected layers with
pooling size is 2*2; padding is 0 and stride is 2. After stochastic gradient descent. By this process, we will
this max pooling operation, we get feature maps of size prepare the trained model which will be used to
32@14*14. Max pooling is done in each feature map recognize the image present in the test data. Thus, we
independently, so we get same number feature maps as can classify the images as Class- airplanes, cars, birds,
the previous layer, and 14 comes from the same formula cats, deer, dogs, frogs, horses, ships, trucks.
((n+2p-f)/s) +1. This layer has no activation function.
Layer-3 is the second convolutional layer with IV. Implementation
ReLu activation function. This layer gets the input of size To implement our CNN architecture, we will use
32@14*14 from the previous layer. The filter size is 5*5; MatConvNet. MatConvNet is an implementation of
padding is 0, the stride is 1, and the number of filters is Convolutional Neural Networks (CNN) for MATLAB [23].
32. After this convolution operation, we get feature maps We built our model by using MatConvNet so that our
of size 32@10*10. Then ReLu activation is done in each model has greater simplicity and flexibility. It exposes
feature map. the building blocks of CNN as easy-to-use MATLAB
functions, providing routines for computing linear
convolutions with filter banks, feature pooling and many initialization parameters for example batch size, number
more. In this manner, MatConvNet allows fast of epochs, learning rate, etc.
prototyping of new CNN architectures; at the same time, The batch size determines the number of
it supports efficient computation on CPU and GPU samples for the training phase of the CNN. The CNN will
allowing to train complex models on large datasets such process all the training data, but only in increments of
as ImageNet ILSVRC. the specified batch size. We can use batch size for
Convolutional Neural Networks (CNN) is the computational efficiency, and its value will be dependent
current state-of-art architecture for the image on the user’s available hardware. An epoch is a
classification task. As shown in Fig.4 our proposed 2-D successful forward pass and a backward pass through
Convolutional Neural Network (CNN) model is designed the network. It’s usually beneficial to set its value high
using MatConvNet backend for the well known CIFAR- and then to reduce it once if one is satisfied with the
10 image recognition task. The whole workflow can be convergence at a particular state (chosen epoch) in the
2 019
to preparing the data, building and compiling the model, network. Learning rate is a very sensitive parameter that
Year
training and evaluating the model and saving the model pushes the model towards convergence. Finding its
to disk for reuse. best value will be an experimental process unless one
16 Preparing the data is the first step of our invokes more powerful techniques such as batch
approach. Before we build the network, we need to set normalization. In our experiment, we use batch size 60,
up our training and testing data, combine data, combine several epochs 300 and learning rate 0.0001 for
Global Journal of Computer Science and Technology ( D ) Volume XIX Issue II Version I
labels and reshape into the appropriate size. We save maximum accuracy.
the dataset of normalized data (single precision and Now we can build our CNN by creating each
zero mean), labels, and miscellaneous (meta) layer individually as shown in fig 5. Afterward, we will
information. invoke objective and error layers that will provide a
Building and compiling the model is the second graphical visualization of the training and validation
step. To create the CNN, we must initialize MatConvNets convergence after completing each epoch. MatconvNet
SimpleNN network and then define important initializes the weights by using Gaussian distribution.
2 019 Year
17
Fig. 6: Objective, Top1error, and Top5error during training
Global Journal of Computer Science and Technology ( D ) Volume XIX Issue II Version I
Finally, by using the testing data, we can
evaluate our model. The following are an example of V. Results and Discussion
classification outputs from the simple network on the Among 10,118 test cases, our model
CIFAR-10 data. misclassifies total of 661 images after three hundred
epochs which correspond to 93.47% recognition rate
shown in Table1. The results are pretty good for three
hundred epochs and for such a simple model with CPU
training and less training time (about 3 hours).
Fig. 7: Some correct recognized outputs Fig. 9: Error rate and accuracy of our model.
Although there are some images which are
difficult to identify, our model will be able to classify
them correctly. For example, our model can recognize
the following image and classify it as ‘deer’:
of training error and test error and ultimately the neural networks. arXiv preprint arXiv:1301.3557,
accuracy can be improved. 2013.
8. Ian J Goodfellow, David Warde-Farley, Mehdi Mirza,
VI. Conclusion and Future Work Aaron Courville, and Yoshua Bengio. Maxout
Here we demonstrate a model which can networks. arXiv preprint arXiv:1302.4389, 2013.
recognize and classify the image. Later it can be 9. Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky,
extended for object recognition, character recognition, Ilya Sutskever, and Ruslan Salakhutdinov‖ Dropout:
and real-time object recognition. Image recognition is an A Simple Way to Prevent Neural Networks from
important step to the vast field of artificial intelligence Overfitting‖ Journal of Machine Learning Research
and computer vision. As seen from the results of the 15 (2014) 1929-1958.
experiment, CNN proves to be far better than other 10. Fabien Lauer, Ching Y. Suen, and G´erard Bloch
―A trainable feature extractor for handwritten digit
2 019
neurons. People can recognize the object from blurry 11. Chen-Yu Lee, Saining Xie, Patrick Gallagher,
images by using our model. Image recognition is an Zhengyou Zhang, Zhuowen Tu, ― Deeply-
18 excellent prototype problem for learning about neural Supervised Nets ―NIPS 2014.
networks, and it gives a great way to develop more 12. M. Fischler and R. Elschlager, ―The representation
and matching of pictorial structures,‖ IEEE
Global Journal of Computer Science and Technology ( D ) Volume XIX Issue II Version I