Deep Learning
1
Topics
Artificial Neural Network
Convolution Neural Network
Recurring Neural Network
Deep Learning
4
Deep Learning
Deep Learning
Synapses
The Activation Function
Types of Activation Functions
Rectifier Leaky Rectifier
Hyperbolic Tangent
Types of Activation Functions
How Neural Networks Work?
X1
X2
X3
X4
Y
Area in (feet)2
Bedrooms
Distance to City
(Miles)
Age
INPUT LAYER OUTPUT LAYER
W2
W1
W3
W4
Price = W1X1 + W2X2 + W3X3 + W4X4
X1
X2
X3
X4
Y
Area in (feet)2
Bedrooms
Distance to City
(Miles)
Age
INPUT LAYER OUTPUT LAYER
H2
H3
H4
H5
H1
HIDDEN LAYER
Feed Forward Neural Network/Perceptron
Perceptron Learning Rule
Perceptron Learning Rule
Gradient Descent
15
Gradient Descent
16
17
Stochastic Gradient Descent
18
Stochastic Gradient Descent
19
Gradient Descent-Backward Propagation
20
Training the ANN with Gradient Descent
21
Building ANN
22
Building ANN
23
Building ANN
24
Building ANN
25
Building ANN
26
Homework
27
Convolution Neural Network
28
What are Convolution Neural Networks?
Step 1  Convolution Operation
Step 1b  ReLU Layer
Step 2  Pooling
Step 3  Flattening
Step 4  Full Connection
Softmax and Cross-Entropy
Convolution Neural Network
29
• How do our brains work?
• How do convolutional neural networks work?
• How do they scan images?
• How do neural networks read facial expressions?
• What are the steps that constitute the convolutional
neural network's process?
What are CNN?
30
Convolution NN
31
Convolution NN
32
Convolution NN
33
Sheepdog or mop?
34
Donald Trump or Raw Chicken
35
Test Set Example
36
Why are CNNs so important?
37
How do CNNs Operate?
38
Convolution NN
39
How CNNs scan images?
40
How CNNs scan images?
41
Detecting Facial Expressions
42
Convolution NN
43
Convolution NN
44
The Convolution Operation
45
How does the Convolution Operation work?
46
How does the Convolution Operation work?
47
How does the Convolution Operation work?
48
How does the Convolution Operation work?
49
How does the Convolution Operation work?
50
How does the Convolution Operation work?
51
How does the Convolution Operation work?
52
How does the Convolution Operation work?
53
How does the Convolution Operation work?
54
How does the Convolution Operation work?
55
The Convolution Operation
56
The Convolution Operation
57
The Convolution Operation
58
The Convolution Operation
59
The Convolution Operation
60
The Convolution Operation
61
The Convolution Operation
62
The Convolution Operation
63
Step 1b: ReLU
64
Step 1b: ReLU
65
Step 1b: ReLU
66
Step 1b: ReLU
67
Step 1b: ReLU
68
Step 2: MaxPooling
69
Step 2: MaxPooling
70
Types of Pooling
1. Mean Pooling
2. Max Pooling
3. Sum Pooling
71
How Pooling works?
72
How Pooling works?
73
How Pooling works?
74
How Pooling works?
75
How Pooling works?
76
How Pooling works?
77
How Pooling works?
78
How Pooling works?
79
How Pooling works?
80
How Pooling works?
81
Convolution and Pooling
82
The Number Game
83
Step 3 Flattening
84
Step 3 Flattening
85
Step 3 Flattening
86
Step 4 Full Connection
87
Step 4 Full Connection
88
Class Recognition
89
Class Recognition
90
Class Recognition
91
Example
92
Example
93
The Convolution Process: A Quick Recap
94
Python code for CNN
95
# Importing the libraries
import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
tf.__version__
# Part 1 - Data Preprocessing
# Preprocessing the Training set
train_datagen = ImageDataGenerator(rescale = 1./255, shear_range =
0.2,zoom_range = 0.2,horizontal_flip = True)
training_set = train_datagen.flow_from_directory
('dataset/training_set',target_size = (64, 64),batch_size = 32,
class_mode = 'binary')
# Preprocessing the Test set
test_datagen = ImageDataGenerator(rescale = 1./255)
test_set = test_datagen.flow_from_directory('dataset/test_set',
target_size = (64, 64),batch_size = 32,class_mode = 'binary')
Python code for CNN
96
# Part 2 - Building the CNN
# Initialising the CNN
cnn = tf.keras.models.Sequential()
# Step 1 - Convolution
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu',
input_shape=[64, 64, 3]))
# Step 2 - Pooling
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
# Adding a second convolutional layer
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu'))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
# Step 3 - Flattening
cnn.add(tf.keras.layers.Flatten())
# Step 4 - Full Connection
cnn.add(tf.keras.layers.Dense(units=128, activation='relu'))
# Step 5 - Output Layer
cnn.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))
Python code for CNN
97
# Part 3 - Training the CNN
# Compiling the CNN
cnn.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
# Training the CNN on the Training set and evaluating it on the Test set
cnn.fit(x = training_set, validation_data = test_set,epochs= 25)
Python code for CNN
98
# Part 4 - Making a single prediction
import numpy as np
from tensorflow.keras.preprocessing import image
test_image = image.load_img('dataset/single_prediction/cat_or_dog_1.jpg', target_size =
(64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = cnn.predict(test_image)
training_set.class_indices
if result[0][0] == 1:
prediction = 'dog'
else:
prediction = 'cat'
print(prediction)
Softmax and Cross-Entropy Functions
99
Softmax Function
100
Cross-Entropy
101
Demonstration
102
Demonstration
103
Demonstration
104
8. Deep Learning.pdf

8. Deep Learning.pdf