My Blog Posts

Video Classification Using CNN with Keras

Video Classification Using CNN with Keras

A model created with a CNN structure is being processed on the basis of the image classification process.

1. What is Convolutional Neural Network (CNN) ?

A CNN model is a neural network used to reveal the attributes of the image. CNN reveals more attributes as layers increase. The fact that the attributes are too high are features that increase image recognition success. There are some layers in the CNN structure, let's take a look at them.

A) Convolutional Layer

In this layer, the attribute is inferred. Some filters are used for these inferences. The working structure of filters is several matrix operations, which means multiplying the main image matrix with another matrix we choose. For example, if you want to

Let's insert a 5×5 image matrix into a 3X3 filter. When we put the filter matrix on the display matrix, let's put overlapping cell values into matrix multiplication and write it a new matrix. The matrix that occurs when we do this on the entire image is our attribute matrix.

Edge Marking (Edge Detection) Filter

Edge information is within attributes obtained from the image. It helps us find high-frequency areas of the image.

Stride (Step Scrolling)

Matrix is a parameter that determines how much the filter is scrolled to when calculating. Direct effects of output size.


After convolutional, it is added to destroy the dimension difference between the input matrix and the output matrix. This is provided with extra pixels to be added to the input matrix.

Filtering process with Padding (Scorecard filter matrix)


Reduces height and width information by keeping the number of channels (RGB or grey) constant. The attribute does not have inference. There are different calculation algorithms such as maximum, average and L2-norm pooling. The working system creates a new matrix by selecting value based on the algorithm used by the image matrix where a filter matrix is navigated.

Max Pooling Example

Output Matrix Discovery Formula

Output Matrix Size Calculated Formula

B) Flattening Layer

The task of this layer is to prepare the data to be sent to The Fully Connected Layer. The process is to translate the matrix from the convolutional pooling layer into a one-dimensional matrix.

C) Fully Connected Layer

It is the part where learning is passed with neural networks.

2.Immensite with Keras

The data set we're going to use will be the CIF-10 data set that comes with keras.

Data Loading

from keras.datasets import cifar10
(x_train,y_train),(x_test,y_test) = cifar10.load_data()

Data Recognition and Display

# explore datadatanum=1000import matplotlib.pyplot as pltimg=plt.imshow(x_train[datanum])#See labelprint("Label:"y_train[datanum])

One Hot Encoding

One Hot Encoding is the process of naming categorical variables binary.

from keras.utils import to_categoricaly_train_ohe=to_categorical(y_train)y_test_ohe=to_categorical(y_test)# y_trainprint y_train_ohe after ohe process

Normalizing image pixels


Creating a Model by Creating a CNN Layer

from keras.models import Sequentialfrom keras.layers import Dense,Flatten,Conv2D,MaxPool2D# Model defined model=Sequential(#CNN and pooling layers are added model.add(Conv2D(32,(5,5),. activation='relu',input_shape=(32,32,3)))))model.add(MaxPool2D(pool_size=(2.2))))))model.add(Conv2D(32,(5,5),activation='relu')))model.add(Conv2D(32,(5,5),activation='relu'))model.add(MaxPool2D(pool_size=(2.2))))#Flatten layer is added model.add(Flatten( )model.add(Dense(1000,activation='relu'relu'relu' ) model.add(Dense(10,activation='softmax') )# 10 neural nodes were howled because there are 10 labels.# Model compilemodel.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])

Model Summary

Measuring and Visualizing Model Success

Success Rate with 150 Epoch

Success and Loss Values

Forecast Ingesting of model

A module named IageClassifiar() has been created. The model was predicted by uploading images through internal storage.

Recording the Trained Model'model_1.h5')

Reusing the Pre-Prepared Model

from keras.models import load_modelmodel=load_model('model_1.h5')

Share this article

Comments (0)