ICP11 - smqhw/kdm1 GitHub Wiki
A. Description About the ICP: This ICP leaned me the implementation of basic CNN model using different hyperparameters.
B. Objective: The main objective of this ICP is to implement a CNN model with a different dataset and find the accuracy of it.
C. Design Implementation: First, I have imported all the libraries to build the model.
About the Dataset: I have used the CIFAR-10 (Canadian Institute For Advanced Research) Dataset for this assignment. The dataset consists of 50,000 32 x 32 color images in 10 classes, with 6,000 images per class. There are 50,000 training images and 10,000 test images. These images are taken in varying lighting conditions and at different angles, and since these are colored images, and we will see that there are many variations in the color itself of similar objects.
Key things are:
Images are colored in CIFAR-100 Each image is 32 x 32 pixel Once loading the data, performed Normalization on that and reduced the pixel values from [0,255] to [-0.5, 0.5]. This will make it easier to train the model.
Now, I've updated the shape values to (32, 32, 3) according to the size of the images (colored) and displayed the shape of each training & Testing image, labels.
Keras expects the training targets to be 10-dimensional vectors since there are 10 nodes in our Softmax output layer. Right now, our train_labels and test_labels arrays contain single integers representing the class for each image. For that, we used "to_categorical". It turns our array of class integers into an array of one-hot vectors instead. For example, 2 would become [0, 0, 1, 0, 0, 0, 0, 0, 0, 0] (it’s zero-indexed).
To build a model, I have considered the below hyperparameters.
num_filters- The number of filters is the number of neurons since each neuron performs a different convolution on the input to the layer (more precisely, the neurons' input weights form convolution kernels). Dropout - Dropouts are the regularization technique that is used to prevent overfitting in the model. Dropouts are added to randomly switching some percentage of neurons of the network. When the neurons are switched off the incoming and outgoing connection to those neurons is also switched off. This is done to enhance the learning of the model. filter_size - It refers to the dimensions of the filter/kernel in the ConvNet (3x3 is the currently most widely used filter size. This is because 3x3 is usually the smallest filter size to do image processing). pool_size - The size of the smaller matrix that will be overlaid upon the feature map. In this example, we will use a value of 2, which indicates that our pooling matrix will be a 2x2 matrix.
Once done with the hyperparameters, we need to build the model with those. Every Keras model is either built using the Sequential class, which represents a linear stack of layers, or the functional Model class, which is more customizable. We’ll be using the simpler Sequential model since our CNN will be a linear stack of layers. The first layer in any Sequential model must specify the input_shape, so we do so on Conv2D. Once this input shape is specified, Keras will automatically infer the shapes of inputs for later layers. The output Softmax layer has 10 nodes, one for each class.
Before we can begin training, we need to configure the training process. We decide on 3 key factors during the compilation.
The optimizer. We’ll stick with a pretty good default: the Adam gradient-based optimizer. The loss function. Since we’re using a Softmax output layer, we’ll use the Cross-Entropy loss. Keras distinguishes between binary_crossentropy (2 classes) and categorical_crossentropy (>2 classes), so we’ll use the latter. A list of metrics. Since this is a classification problem, we’ll just have Keras report on the accuracy metric.
The next step is Model training. Training a model in Keras used by calling fit() function.
With this model, we achieved an accuracy of 0.5946.
In the last step, We are displaying the model outcomes with actual values.
D. Video Link: Submitted in Code file. E. Conclusion:
- What you have learned from the ICP - In this ICP, I have learned how to build a basic CNN model and finding the Accuracy of the model.
- What challenges you have faced - I did not face any challenges while doing the ICP.