1 of 33

Convolutional Neural Networks_Ex

1

2/21/2023

Dr. Dinesh Kumar Vishwakarma�Professor, Department of Information Technology�Delhi Technological University, Delhi

Email: dinesh@dtu.ac.in

Web page: http://www.dtu.ac.in/Web/Departments/InformationTechnology/faculty/dkvishwakarma.php

Biometric Research Laboratory

http://www.dtu.ac.in/Web/Departments/InformationTechnology/lab_and_infra/bml/

2 of 33

What is CNN?

2

2/21/2023

3 of 33

CNN Benefits

3

2/21/2023

  • Equivariant activities: Replicated features do not make the neural activities invariant to translation. The activities are equivariant.

  • Invariant Knowledge: If a feature is useful in some locations during training, detectors for that feature will be available in all locations during testing.

Representation by active neurons

image

Translated representation

translated image

Courtesy: Geoffrey Hinton CSC2535

4 of 33

How CNN Works?

4

2/21/2023

5 of 33

Possible Case

5

2/21/2023

6 of 33

How CNN Works?

6

2/21/2023

7 of 33

How CNN Works?

7

2/21/2023

8 of 33

How CNN Works?

8

2/21/2023

Gives an idea

9 of 33

How CNN Works?

9

2/21/2023

First Filter

Second Filter

Third Filter

10 of 33

How CNN Works?

10

2/21/2023

11 of 33

How CNN Works?

11

2/21/2023

12 of 33

Convolutional Layer

12

2/21/2023

13 of 33

Operations Involved in Convolution Layer

  • Move filter over the image at every possible position.
  • Multiply each image pixel by corresponding feature pixel.

13

2/21/2023

Similarly

14 of 33

Operations Involved in Convolution Layer…

  • Adding all the multiplied values of filter at every move.
  • Divide the sum by total number of pixels.

14

2/21/2023

O/P of Conv Layer for first filter

15 of 33

Output of Convolutional Layer

15

2/21/2023

16 of 33

Activation Layer: ReLU

16

2/21/2023

17 of 33

ReLU: Removes the Negative Values

17

2/21/2023

First Feature

1st Feature

2nd Feature

3rd Feature

18 of 33

Pooling Layer

18

2/21/2023

19 of 33

Max Pooling of size: 2x2, Stride : 2

19

2/21/2023

7x7

4x4

.77

20 of 33

Max Pooling of size: 2x2, Stride : 2

20

2/21/2023

.77

7x7

7x7

7x7

4x4

4x4

4x4

21 of 33

Stacking of Layers

21

2/21/2023

i-th layer of CNN

Convolutional Layer

22 of 33

Practical CNN Model

  • Most of the practical CNN models have more number of layers.

22

2/21/2023

2x2

2x2

2x2

23 of 33

Fully Connected Layer

  • Actual Classification Occurs at FC layer

23

2/21/2023

Flattened the final output layer

24 of 33

Output

24

2/21/2023

“1” at

1

2

3

4

5

6

7

8

9

10

11

12

1

2

3

4

5

6

7

8

9

10

11

12

25 of 33

Prediction

25

2/21/2023

Now Network is training and gives prediction for a Test sample

Is is “X” or “O”?

Lets Compare

1

2

3

4

5

6

7

8

9

10

11

12

26 of 33

Prediction: Compare with ‘X’ and ‘O’

26

2/21/2023

1

2

3

4

5

6

7

8

9

10

11

12

For ‘X’

1

2

3

4

5

6

7

8

9

10

11

12

27 of 33

Prediction: Compare with ‘X’ and ‘O’

27

2/21/2023

For ‘O’

1

2

3

4

5

6

7

8

9

10

11

12

1

2

3

4

5

6

7

8

9

10

11

12

28 of 33

Result: Compare with ‘X’ and ‘O’

28

2/21/2023

Classified as “X”

What is result?

29 of 33

CNN for Edge Detection

29

2/21/2023

30 of 33

Implementation of CNN

The CIFAR-10 dataset: This dataset consists of 60000 32x32 colour images in 10 classes, with 6000 images per class.

30

2/21/2023

31 of 33

Model of CNN

31

2/21/2023

32 of 33

Implementation in TensorFlow

def createModel():

model = Sequential()

# The first two layers with 32 filters of window size 3x3

model.add(Conv2D(32, (3, 3), padding='same', activation='relu', input_shape=input_shape))

model.add(Conv2D(32, (3, 3), activation='relu'))

model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))

model.add(Conv2D(64, (3, 3), activation='relu'))

model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))

model.add(Conv2D(64, (3, 3), activation='relu'))

model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Dropout(0.25))

model.add(Flatten())

model.add(Dense(512, activation='relu'))

model.add(Dropout(0.5))

model.add(Dense(nClasses, activation='softmax'))

return model

32

2/21/2023

33 of 33

References

33

2/21/2023