0% found this document useful (0 votes)
9 views57 pages

Deep 2

The document discusses a deep learning case study involving image classification using small images from the CIFAR-10 dataset, focusing on techniques such as dropout regularization, precision, recall, and handling imbalanced datasets. It also covers the differences between artificial neural networks (ANN) and convolutional neural networks (CNN), emphasizing the importance of feature detection and pooling operations in CNNs for improved image recognition. Additionally, it addresses practical applications in fields like computer vision and fraud detection, along with methods for managing class imbalances in datasets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views57 pages

Deep 2

The document discusses a deep learning case study involving image classification using small images from the CIFAR-10 dataset, focusing on techniques such as dropout regularization, precision, recall, and handling imbalanced datasets. It also covers the differences between artificial neural networks (ANN) and convolutional neural networks (CNN), emphasizing the importance of feature detection and pooling operations in CNNs for improved image recognition. Additionally, it addresses practical applications in fields like computer vision and fraud detection, along with methods for managing class imbalances in datasets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Deep Learning

Module 2

DSE 5212
By: Dr.Rashmi L MALGHAN
Case Study:
Small Images : 10 classes
Example:
• We are using 60000 small images for classification. These images can be classified in one of the
10 categories below, classes =
["airplane","automobile","bird","cat","deer","dog","frog","horse","ship","truck"]
• CIFAR-10 and CIFAR-100 datasets
• Using ANN
• How to Install TensorFlow with GPU Support on Windows - Shawn Hymel
BENCHMARKING
(GPU ,CPU)
GPU bench-marking with image classification
To check Accuracy: Use evaluate function

Run Performance on both models: Need to


define function get_model()
Code link:
deep-learning-keras-tf-
tutorial/10_gpu_benchmarking/gpu_performance_test_small_
image_classification.ipynb at master · codebasics/deep-
learning-keras-tf-tutorial · GitHub
10
PRECISION,
RECALL,
ACCURACY & F1-
SCORE
True Positive, False Positive, True
Negative, False Negative, Accuracy
◦ Prediction:
◦ Positive Predictions: Total 7 dog predictions.
◦ Out of 7 how many are correct: 4,wrong 3.
◦ True Positive:4
◦ False Positive:3 (1st word : False – Indicates the
“reality”,2nd word : Positive- Indicates the
outcome of the prediction)
◦ Negative Predictions:
◦ True Negative: 1
◦ False negative :2

12
PRECISION,
RECALL: FOR
DOG CLASS

13
PRECISION,
RECALL: FOR NOT
DOG CLASS
&
PRECISION

• How many no dog


samples i have : 4

14
• True positive:
• 4 times I predicted truth as dog.
• 2 time I predicted truth as not dog.
• 3 time I predicted it as dog as it was not a
dog
• 1 time it was not a dog I predicted it to be
bot a dog.
• Anything in diagonal is all right
predictions.

15
DROPOUT
REGULARIZATION
Dropout Regularization
• Complex dataset will have many
hidden layers with lot of neurons init.
• So NN will try to overfit the dataset .
• So it will not perform well with test
dataset.

• Drop randomly any neurons a the rate of 50%


from hidden layers, Addressing on the overfitting
• After dropping it will not create any kind of bias
as it can be used to remove redundant learning.

17
deep-learning-keras-tf-tutorial/13_dropout_layer at master · codebasics/deep-
learning-keras-tf-tutorial · GitHub

18
Drop Regularization
• In the dataset there is no column
nae so specified header=none.
• It uses integer sequence as
column names.

19
• Y has text data so
one hot encoding,
convert to int

20
ANN Building

21
22
Adding Dropout layer to model:

• Using dropout at random rate the


accuracy has reduced to 0.8 on
training set.
• Its ok as we care more about testing

• In testing the accuracy


has increased from 75
to 80%. Even F1 score
is important
23
IMBALANCE DATASET:
HANDLING
Scenario : Fraud Detection
◦ An imbalanced dataset is where the classes in your target variable are not
equally represented, which can cause poor performance of the model.
◦ Training Dataset : Assume considered size is 20,000. In that 20,000 transactions
we find only 1 fraud transaction. This creates an imbalance.

• This function returns false as majority of


transactions are true.
• Model (function) is performing horrible
even if its accuracy is 99%.
• Ways to tackle this kind of imbalance
dataset.
• Under sampling majority class:
• Over Sampling Minority Class by
duplication. 25
UNDER
SAMPLING-
MAJORITY
CLASS
• Under sampling majority class: (1000 samples
belonging to red class -Fraud, 99000 samples
belonging to green class - non-fraud).
• Take randomly picked 1000 samples from 99000
samples. And discard remaining samplings.
Combine with 1000 red samples and train the
model.
26
Over Sampling
Minority Class by
duplication

• Over Sampling Minority Class : (Duplicate 1000


samples (Transactions) by 99 times belonging to red
class –Fraud (we get 99000 transactions), 99000
samples belonging to green class - non-fraud) and
train the model.

27
Over Sampling
Minority Class using
SMOTE

• Over Sampling Minority Class : Use K nearest


neighbours algorithm.
• Try to produce synthetic samples from your
1000- samples.
• In python there is “imblearn” library specifically
designed to handle imbalance datasets.
28
Majority Vote

ENSEMBLE

• Ensemble: Assume you have 3000 in one class


and 1000 in another class.
• We can divide 3000 in 3 batches.
• Combine 1st batch with 1000 sample class, say it
to be model 1. Similarly do it for other batches and
create model 2 and 3.
• Use majority vote( something like random
29
How Focal Loss fixes the Class Imbalance problem in

FOCAL Object Detection | by Yash Marathe | Analytics Vidhya |


Medium

LOSS

30
APPLICATIONS: IMBALANCE DATASETS

31
Applications:
Computer vision – DL
(CNN)
◦ Image classification, Video processing, Object
detection – Field – Computer Vision.

◦ Usage of google lens: To detect the information


about specific plant.

◦ Gallery : I would have dumped many photos. In


that if I want to search fruit images I just type
fruit it will give me classification of all fruit
images.

◦ Identify People: If u just click the specific


people picture . U will get respective pictures of
them.

32
Banking & Agriculture

◦ Cheque Deposition.
◦ I take image of check , it will do image recognition, check number, cheque number. It will
automatically done by filling the information (Bank of America How to Deposit check on
mobile phone | Bank of America
◦ Detecting the apples on tree : To predict the yield. (“Product developers and technology
consultants: Cambridge Consultants”). AI and the future of agriculture

33
Why traditionally humans are better at image
recognition than computers?

Disadvantages of using traditional artificial neural


network (ANN) for image classification.

CNN: How human brain recognizes images?

Convolution How computers can use filters for feature detection

Neural
Network
What is convolution operation and how it works

Importance of ReLU activation in CNN

Importance of pooling operation in CNN 8. How to


handle rotation and scale in CNN

34
• Way how computer look at
this is grid of numbers. Here i
m considering it to be -1 and 1
representation.
• In reality it uses RGB number
Location Shift 0 to 255

• Issue is its too much hard coded.


• If we have little shift in digit “9”. There
will be no matching. The representation
of the number changes so computer will
not be able to recognize the digit.

• There could be variations on how we write the


digit.
• Which will change 2D re presentations of the
number. So we use ANN to handle the variety.

35
Why not ANN?
◦ ANN works well for simple image
applications like handwritten digits.
◦ If for complex images ANN doesn’t
hold good.
◦ 24 million weights to be calculated
between input and hidden layers.

36
37
COMPARISON
TABLE

38
WHEN TO
USE
ANN V/S
CNN

39
How Does Human Recognize images : So Easily

40
How Does Human
Recognize images : So
Easily
◦ In human brain we use some neurons to
concentrate on tiny features.
◦ Different neurons to aggregate the results.

41
How can we make computers to learn these tiny
features:
◦ By using the concept of “filters”

• In this case study : There


are 3 filters.
• Loopy filter :To take
care of head part.
• Vertical Line filter:
Middle line area.
• Diagonal Line filter:
Diagonal area.

42
Feature Mapping:
• We take original image, we apply convolution operation
• Feature Mapping is done: 3*3 gird data from original image gets mapped with 1st filter
(i.e. loop filter).
• Fetaure mapping: Multiply the original grid values with the filter value divide it by total
number of grid data we considered (i.e 9).
• Ex: (-1*1+1*1+1*1+-1*1+1*-1+-1*1+-1*1+1*1+1*1)/9 = -0.11

43
• Search for the value 1 or closer to 1.
• This is detecting feature. In case koala it might be eyes or nose by moving
the filter through out the image.
• Feature got activate where the value is close to 1 or 1.

44
Cases:

• Based on the value


the respective
feature gets
activated.

Note: Filters are the nothing but the


feature detectors.
45
CNN:
LOCATION
INVARIANT:
EYES
DETECTION

46
HANDS
DETECTOR

47
DIGIT
RECOGNITION

• In case of “9”: We
need to apply 3
filters (i.e. head,
middle & tail).
• we go three feature
maps.

48
Feature Map
Representation:

• In any articles or
books the Feature
Map is represented
like shown in figure
(its like stack
together).

• They form the 3D


volume

49
• Filter Can be 3D.
• 1st slice may be representing : eyes, 2nd slice : nose, 3rd slice: ears.
• By doing that filter we can say that koala head is on the specific region (right side)
of an image.
• Aggregating different results (eyes, nose, ears) to get new feature map (head).

50
• Here it is different koala image.
• Thus it create different flatten array.
• NN handles variety: So it can handle variety input

51
• We use ReLU activation to bring the non-linearity in our model.
• It will take feature map and what ever negative values replace with “0”. Other values
keep it as it is.
• ReLU helps with making model non-linear: It makes bunch of values to be “0”

52
• For this image size if we are applying CNN with some padding we are still
getting same image size. Image size is Sometimes they don't use padding ,
they reduce image size but only little bit.
• So pooling is used to “reduce the size” 53
54
MAX
POOLING

• Take feature map apply pooling generate


the new feature map.
• New feature map is half the size.
• Reduced 16 numbers to 4.
• Too much saving in computation
• 2 stride further : Move 2 pixels (places)
55
further
Handwritten Digit : 1 stride

• Loopy feature at the top.


• Max pooling along with convolution
helps with position invariant feature
detection doesn’t matter were eyes or
ears are in the images.

56

You might also like