SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Technical Skills-2(Tensorflow)
Topic:
CNN WITH TENSOR FLOW
Department of IoT
Exp- 3
AIM OF THE SESSION
To familiarize students with the concept of CNN
INSTRUCTIONAL OBJECTIVES
This Session is designed to:
1. CNN application
2. CNN architecture
LEARNING OUTCOMES
At the end of this session, you should be able to:
1. Able to understand CNN learning model
The topics covered in the session are
1. What is need for CNN
2. Differences between CNN and ANN
3. CNN architecture
4. Convolution operation
5. Pooling techniques
3
SESSION Introduction
1. WHAT DO YOU SEE, AND HOW?
CAN WE TEACH MACHINES TO SEE?
WHAT DO YOU SEE?
HOW DO YOU SEE?
How can we help computers see?
WHAT COMPUTERS ‘SEE’: IMAGES AS NUMBERS
What you see What you both see What the computer "sees"
Levin
Image
Processing
&
Computer
Vision
Input Image Input Image + values Pixel intensity values
(“pix-el”=picture-element)
An image is just a
matrix of numbers
[0,255]. i.e.,
1080x1080x3 for an
RGB image.
Question: is this
Lincoln? Washington?
Jefferson? Obama?
•How can the computer
answer this question?
Can I just do
classification on the
1,166400-long image
vector directly?
No. Instead: exploit
image spatial
structure. Learn
patches. Build them
up
2. CLASSICAL MACHINE VISION ROOTS
IN STUDY OF HUMAN/ANIMAL BRAINS
INSPIRATION: HUMAN/ANIMAL VISUAL CORTEX
• Layers of neurons: pixels, edges, shapes, primitives, scenes
• E.g. Layer 4 responds to bands w/ given slant, contrasting edges
PRIMITIVES:NEURONS &ACTION
POTENTIALS
• Chemical accumulation across
dendritic connections Pre-synaptic axon
• post-synaptic dendrite
• neuronal cell body
• Each neuron receives multiple signals from
its many dendrites When threshold crossed,
it fires
• Its axon then sends outgoing signal to
downstream neurons
• Weak stimuli ignored
• Sufficiently strong cross activation
threshold
• Non-linearity within each
neuronal level
• Neurons connected into circuits (neural networks): emergent properties, learning, memory
• Simple primitives arranged in simple, repetitive, and extremely large networks
• 86 billion neurons, each connects to 10k neurons, 1 quadrillion (1012) connections
ABSTRACTION LAYERS: EDGES, BARS, DIR., SHAPES,
OBJECTS, SCENES
LGN: Small dots
V1: Orientation, disparity, some
color
V4: Color, basic shapes, 2D/3D, curvature
VTC: Complex features and objects(VTC:
ventral temporal cort
e
• Abstraction layers  visual cortex layers
• Complex concepts from simple parts, hierarchy
• Primitives of visual concepts encoded in
neuronal connection in early cortical layers
• Massive recent expanse of human brain has re-used a relatively simple but general
learning architecture
GENERAL“LEARNINGMACHINE”,REUSED WIDELY
• Hearing, taste, smell, sight, touch all re- use similar
learning architecture
Visual Cortex Motor Cortex • Interchangeable circuitry
• Auditory cortex learns to ‘see’
if sent visual signals
• Injury area tasks shift to
uninjured areas
• Not fully-general learning, but well-adapted to our world
• Humans co-opted this circuitry to many new applications
• Modern tasks accessible to any homo sapiens (<70k years)
• ML primitives not too different from animals: more to come?
human
chimp
Hardware
expansion
WHAT IS CNN?
Convolutional Neural Networks (CNN) is a feed forward neural
network that is generally used for Image recognition and object
classification.
CNNs are inspired from the visual cortex of the brain and have been
widely applied in image and speech recognition.
Cnn represent a huge breakthrough in image recognition
WHY CNN
Until quite recently, computers were not good at tasks
like recognizing puppy in a picture or recognizing
spoken words, which humans excel at.
• The CNN is essential when it comes to image classification
problems since it has such a high degree of accuracy.
• Prior to training an Artificial Neural Network, a 2D image is
converted into a 1-dimensional vector.
• Furthermore, as the image size increases, the number of
training parameters increases exponentially, leading to
storage loss.
• ANNs do not capture the sequence information that
sequence data requires.
CNN VS ANN
1.
2 For small images it might work, but for large
images the no of pixels are so many leading to
millions of connections between neurons, leading to
intractable solutions 2. No of features /pixels are reduced thru
convolution and pooling operations
15
Deep learning
• In an ANN, each neuron in the network is
connected to every other neuron in the
adjacent hidden layers.
1. In a CNN, each neuron in the hidden layer is
connected to a small region of the input neurons.
CNN ARCHITECTURE
• A CNN typically has three layers: a convolutional layer, a pooling layer, and a fully connected
layer.
Deep learning 16
CNN ARCHITECTURE CONT..
17
CNN ARCHITECTURE: TYPES OF LAYERS
• Convolutional layer
• a “filter” passes over the image, scanning a
few pixels at a time and creating a feature
map that predicts the class to which each
feature belongs.
• Pooling layer (downsampling)
• reduces the amount of information in each
feature obtained in the convolutional layer
while maintaining the most important
information .
• there are usually several rounds of
convolution and pooling.
2/25/2024 Deep learning 18
CNN ARCHITECTURE: TYPES OF LAYERS
• Fully connected input layer (flatten)
• It takes the output of the previous layers,
“flattens” them and turns them into a
single vector that can be an input for the
next stage.
• The first fully connected layer takes the
inputs from the feature analysis and
applies weights to predict the correct
label.
• Fully connected output layer gives the
final probabilities for each label.
2/25/2024 Deep learning 19
4.CONVOLUTIONS AND FILTERS
CONVOLUTION OPERATION IS ELEMENT WISE MULTIPLY
AND ADD
Filter / Kernel
PRODUCING FEATURE MAPS
Original Sharpen Edge Detect “Strong” Edge
Detect
A SIMPLE PATTERN: EDGES
HOW CAN WE DETECT EDGES WITH A KERNEL?
Input
1 -1
Filter
Output
SIMPLE KERNELS / FILTERS
X OR X?
Image is represented as matrix of pixel values… and computers are literal!
We want to be able to classify an X as an X even if it’s shifted, shrunk, rotated, deformed.
CONVOLUTION
PROCESS
• Assume the filter/kernel is weight
matrix wk
. For example, lets
assume a 3 x 3 weighted matrix.
• The kernel is a filter to extract
some particular features from the
original images.
• It could be for extracting curves ,
identifying a specific colour, or
recognizing a particular voice.
Deep learning 26
CONVOLUTION
OPERATION
• Kernel/Filter, K =
• 1 0 1
0 1 0
1 0 1
27
PROCESS OF CONVOLUTION (CONTD.)
0 1 1
1 0 0
1 0 1
Input layer Filter/Kernel
(Weighted matrix)
515
• For example, when the weighted matrix starts from the top left corner of the input layer, the
output value is calculated as:
(81x0+2x1+209x1)+(24x1+56x0+108X0)+(91x1+0x0+189x1) = 515
81 2 209 44 71 58
24 56 108 98 12 112
91 0 189 65 79 232
12 0 0 5 1 71
2 32 23 58 8 209
49 98 81 112 54 9
EXAMPLE
• As the filter/kernel is slided across the input layer, the convolved layer is obtained by
adding the values obtained by element wise multiplication of the weight matrix.
Output
PROCESS OF CONVOLUTION (CONTD.)
0 1 1
1 0 0
1 0 1
Input layer
Filter/Kernel
(Weighted matrix)
Output
(Activation/Feature Map)
515 374
• Dimension of output=n-f+1
• The distance between two consecutive receptive fields is called the stride.
• In this example stride is 1 since the receptive field was moved by 1 pixel at a time.
81 2 209 44 71 58
24 56 108 98 12 112
91 0 189 65 79 232
12 0 0 5 1 71
2 32 23 58 8 209
49 98 81 112 54 9
EXAMPLE
• The filter then moves by 1 pixel to the next receptive field and the process is repeated. The output layer
obtained after the filter slides over the entire image would be a 4X4 matrix.This is called an activation map/
feature map.
30
Calculating output dimension of Convolution
layer
ReLU Layer
31
• ReLU stands for Rectified Linear Unit and is a non-linear operation.
• ReLU is an element wise operation (applied per pixel) and replaces all
negative pixel values in the feature map by zero.
Output = Max(zero, Input)
Pooling Layer (Sub-sampling or Down-sampling)
• Pooling layer reduce the size of feature maps by using some functions to summarize sub-
regions, such as taking the average or the maximum value
FULLY CONNECTED LAYER
After completion of series of convolutional, nonlinear and pooling layers, it is
necessary to attach a fully connected layer.
This layer takes the output information from convolutional networks.
Attaching a fully connected layer to the end of the network results in an N
dimensional vector, where N is the number of classes from which the model
selects the desired class.
33
Deep learning
EXAMPLE
AN IMAGE CLASSIFICATION CNN
CNNS FOR CLASSIFICATION
• Train model with image data.
• Learn weights of filters in convolutional layers. D
tf.keras.activations.
*
tf.keras.layers.MaxPool2
D
Convolution:Apply
filters to generate
feature maps.
Non-linearity: Often
ReLU.
Pooling:
Downsampling
operation on each
feature map.
tf.keras.layers.Conv2
CNNS FOR CLASSIFICATION: FEATURE LEARNING
Learn features in input image through convolution
Learn
Introduce non-linearity through activation function (real-world data is non-linear!)
Introduce
Reduce dimensionality and preserve spatial invariance with pooling
Reduce
CNNS FOR CLASSIFICATION: CLASS PROBABILITIES
CONV and POOL layers output high-level features of input
Fully connected layer uses these features for classifying input image
Express output as probability of image belonging to a particular class
REPRESENTATION LEARNING IN DEEP CNNS
Mid level features
Low level features High level features
Edges, dark spots
Conv Layer 1
Eyes, ears,nose
Conv Layer 2
Facial structure
Conv Layer 3
EXAMPLE – SIX CONVOLUTIONAL LAYERS
CONVOLUTIONAL LAYERS: LOCAL
CONNECTIVITY
For a neuron in
hidden layer:
• Take inputs from
patch
• Compute
weighted sum
• Apply bias
tf.keras.layers.
Conv2D
CONVOLUTIONAL LAYERS: LOCAL
CONNECTIVITY
For a neuron in hidden layer:
• Take inputs from patch
• Compute weighted sum
• Apply bias
4x4 filter:
matrix of
weights wij
for neuron (p,q) in hidden layer
1) applying a window of weights
2) computing linear combinations
3) activating with non-linear function
tf.keras.layers.Conv2D
OTHER ARCHITECTURES OFCNN
LeNet-5 (1998) • AlexNet (2012) ZFNet (2013)
GoogLeNet (2014) VGGNet(2014) ResNet (2015)
• Over the years, many variants of this basic architecture have been developed such as:
• These models can be used in applications by developers.
THANK YOU
2/25/2024
44
Deep learning

Weitere ähnliche Inhalte

Ähnlich wie build a Convolutional Neural Network (CNN) using TensorFlow in Python

Convolutional Neural Networks
Convolutional Neural NetworksConvolutional Neural Networks
Convolutional Neural Networksmilad abbasi
 
Convolutional Neural Networks (CNN)
Convolutional Neural Networks (CNN)Convolutional Neural Networks (CNN)
Convolutional Neural Networks (CNN)Gaurav Mittal
 
convolutional_neural_networks in deep learning
convolutional_neural_networks in deep learningconvolutional_neural_networks in deep learning
convolutional_neural_networks in deep learningssusere5ddd6
 
Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018
Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018
Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018Universitat Politècnica de Catalunya
 
Introduction to computer vision with Convoluted Neural Networks
Introduction to computer vision with Convoluted Neural NetworksIntroduction to computer vision with Convoluted Neural Networks
Introduction to computer vision with Convoluted Neural NetworksMarcinJedyk
 
Fundamental of deep learning
Fundamental of deep learningFundamental of deep learning
Fundamental of deep learningStanley Wang
 
Introduction to computer vision
Introduction to computer visionIntroduction to computer vision
Introduction to computer visionMarcin Jedyk
 
CONVOLUTIONAL NEURAL NETWORK
CONVOLUTIONAL NEURAL NETWORKCONVOLUTIONAL NEURAL NETWORK
CONVOLUTIONAL NEURAL NETWORKMd Rajib Bhuiyan
 
04 Deep CNN (Ch_01 to Ch_3).pptx
04 Deep CNN (Ch_01 to Ch_3).pptx04 Deep CNN (Ch_01 to Ch_3).pptx
04 Deep CNN (Ch_01 to Ch_3).pptxZainULABIDIN496386
 
Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...
Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...
Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...Sergey Karayev
 
A brief introduction to recent segmentation methods
A brief introduction to recent segmentation methodsA brief introduction to recent segmentation methods
A brief introduction to recent segmentation methodsShunta Saito
 
Handwritten Digit Recognition and performance of various modelsation[autosaved]
Handwritten Digit Recognition and performance of various modelsation[autosaved]Handwritten Digit Recognition and performance of various modelsation[autosaved]
Handwritten Digit Recognition and performance of various modelsation[autosaved]SubhradeepMaji
 
Overview of Convolutional Neural Networks
Overview of Convolutional Neural NetworksOverview of Convolutional Neural Networks
Overview of Convolutional Neural Networksananth
 
Introduction to deep learning
Introduction to deep learningIntroduction to deep learning
Introduction to deep learningJunaid Bhat
 
Deep Neural Network DNN.docx
Deep Neural Network DNN.docxDeep Neural Network DNN.docx
Deep Neural Network DNN.docxjaffarbikat
 

Ähnlich wie build a Convolutional Neural Network (CNN) using TensorFlow in Python (20)

Convolutional Neural Networks
Convolutional Neural NetworksConvolutional Neural Networks
Convolutional Neural Networks
 
Convolutional Neural Networks (CNN)
Convolutional Neural Networks (CNN)Convolutional Neural Networks (CNN)
Convolutional Neural Networks (CNN)
 
convolutional_neural_networks in deep learning
convolutional_neural_networks in deep learningconvolutional_neural_networks in deep learning
convolutional_neural_networks in deep learning
 
Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018
Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018
Convolutional Neural Networks - Veronica Vilaplana - UPC Barcelona 2018
 
Introduction to computer vision with Convoluted Neural Networks
Introduction to computer vision with Convoluted Neural NetworksIntroduction to computer vision with Convoluted Neural Networks
Introduction to computer vision with Convoluted Neural Networks
 
Fundamental of deep learning
Fundamental of deep learningFundamental of deep learning
Fundamental of deep learning
 
Introduction to computer vision
Introduction to computer visionIntroduction to computer vision
Introduction to computer vision
 
cnn-170917175001 (1).pdf
cnn-170917175001 (1).pdfcnn-170917175001 (1).pdf
cnn-170917175001 (1).pdf
 
CONVOLUTIONAL NEURAL NETWORK
CONVOLUTIONAL NEURAL NETWORKCONVOLUTIONAL NEURAL NETWORK
CONVOLUTIONAL NEURAL NETWORK
 
04 Deep CNN (Ch_01 to Ch_3).pptx
04 Deep CNN (Ch_01 to Ch_3).pptx04 Deep CNN (Ch_01 to Ch_3).pptx
04 Deep CNN (Ch_01 to Ch_3).pptx
 
Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...
Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...
Lecture 2.B: Computer Vision Applications - Full Stack Deep Learning - Spring...
 
B.tech_project_ppt.pptx
B.tech_project_ppt.pptxB.tech_project_ppt.pptx
B.tech_project_ppt.pptx
 
A brief introduction to recent segmentation methods
A brief introduction to recent segmentation methodsA brief introduction to recent segmentation methods
A brief introduction to recent segmentation methods
 
Cnn
CnnCnn
Cnn
 
Handwritten Digit Recognition and performance of various modelsation[autosaved]
Handwritten Digit Recognition and performance of various modelsation[autosaved]Handwritten Digit Recognition and performance of various modelsation[autosaved]
Handwritten Digit Recognition and performance of various modelsation[autosaved]
 
Deep learning (2)
Deep learning (2)Deep learning (2)
Deep learning (2)
 
Overview of Convolutional Neural Networks
Overview of Convolutional Neural NetworksOverview of Convolutional Neural Networks
Overview of Convolutional Neural Networks
 
Introduction to deep learning
Introduction to deep learningIntroduction to deep learning
Introduction to deep learning
 
Mnist report
Mnist reportMnist report
Mnist report
 
Deep Neural Network DNN.docx
Deep Neural Network DNN.docxDeep Neural Network DNN.docx
Deep Neural Network DNN.docx
 

Kürzlich hochgeladen

....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdfVikramadityaRaj
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxCeline George
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryEugene Lysak
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Celine George
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024CapitolTechU
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxMohamed Rizk Khodair
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Mark Carrigan
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 

Kürzlich hochgeladen (20)

....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 

build a Convolutional Neural Network (CNN) using TensorFlow in Python

  • 1. Technical Skills-2(Tensorflow) Topic: CNN WITH TENSOR FLOW Department of IoT Exp- 3
  • 2. AIM OF THE SESSION To familiarize students with the concept of CNN INSTRUCTIONAL OBJECTIVES This Session is designed to: 1. CNN application 2. CNN architecture LEARNING OUTCOMES At the end of this session, you should be able to: 1. Able to understand CNN learning model
  • 3. The topics covered in the session are 1. What is need for CNN 2. Differences between CNN and ANN 3. CNN architecture 4. Convolution operation 5. Pooling techniques 3 SESSION Introduction
  • 4. 1. WHAT DO YOU SEE, AND HOW? CAN WE TEACH MACHINES TO SEE?
  • 5. WHAT DO YOU SEE?
  • 6. HOW DO YOU SEE? How can we help computers see?
  • 7. WHAT COMPUTERS ‘SEE’: IMAGES AS NUMBERS What you see What you both see What the computer "sees" Levin Image Processing & Computer Vision Input Image Input Image + values Pixel intensity values (“pix-el”=picture-element) An image is just a matrix of numbers [0,255]. i.e., 1080x1080x3 for an RGB image. Question: is this Lincoln? Washington? Jefferson? Obama? •How can the computer answer this question? Can I just do classification on the 1,166400-long image vector directly? No. Instead: exploit image spatial structure. Learn patches. Build them up
  • 8. 2. CLASSICAL MACHINE VISION ROOTS IN STUDY OF HUMAN/ANIMAL BRAINS
  • 9. INSPIRATION: HUMAN/ANIMAL VISUAL CORTEX • Layers of neurons: pixels, edges, shapes, primitives, scenes • E.g. Layer 4 responds to bands w/ given slant, contrasting edges
  • 10. PRIMITIVES:NEURONS &ACTION POTENTIALS • Chemical accumulation across dendritic connections Pre-synaptic axon • post-synaptic dendrite • neuronal cell body • Each neuron receives multiple signals from its many dendrites When threshold crossed, it fires • Its axon then sends outgoing signal to downstream neurons • Weak stimuli ignored • Sufficiently strong cross activation threshold • Non-linearity within each neuronal level • Neurons connected into circuits (neural networks): emergent properties, learning, memory • Simple primitives arranged in simple, repetitive, and extremely large networks • 86 billion neurons, each connects to 10k neurons, 1 quadrillion (1012) connections
  • 11. ABSTRACTION LAYERS: EDGES, BARS, DIR., SHAPES, OBJECTS, SCENES LGN: Small dots V1: Orientation, disparity, some color V4: Color, basic shapes, 2D/3D, curvature VTC: Complex features and objects(VTC: ventral temporal cort e • Abstraction layers  visual cortex layers • Complex concepts from simple parts, hierarchy • Primitives of visual concepts encoded in neuronal connection in early cortical layers
  • 12. • Massive recent expanse of human brain has re-used a relatively simple but general learning architecture GENERAL“LEARNINGMACHINE”,REUSED WIDELY • Hearing, taste, smell, sight, touch all re- use similar learning architecture Visual Cortex Motor Cortex • Interchangeable circuitry • Auditory cortex learns to ‘see’ if sent visual signals • Injury area tasks shift to uninjured areas • Not fully-general learning, but well-adapted to our world • Humans co-opted this circuitry to many new applications • Modern tasks accessible to any homo sapiens (<70k years) • ML primitives not too different from animals: more to come? human chimp Hardware expansion
  • 13. WHAT IS CNN? Convolutional Neural Networks (CNN) is a feed forward neural network that is generally used for Image recognition and object classification. CNNs are inspired from the visual cortex of the brain and have been widely applied in image and speech recognition. Cnn represent a huge breakthrough in image recognition
  • 14. WHY CNN Until quite recently, computers were not good at tasks like recognizing puppy in a picture or recognizing spoken words, which humans excel at. • The CNN is essential when it comes to image classification problems since it has such a high degree of accuracy. • Prior to training an Artificial Neural Network, a 2D image is converted into a 1-dimensional vector. • Furthermore, as the image size increases, the number of training parameters increases exponentially, leading to storage loss. • ANNs do not capture the sequence information that sequence data requires.
  • 15. CNN VS ANN 1. 2 For small images it might work, but for large images the no of pixels are so many leading to millions of connections between neurons, leading to intractable solutions 2. No of features /pixels are reduced thru convolution and pooling operations 15 Deep learning • In an ANN, each neuron in the network is connected to every other neuron in the adjacent hidden layers. 1. In a CNN, each neuron in the hidden layer is connected to a small region of the input neurons.
  • 16. CNN ARCHITECTURE • A CNN typically has three layers: a convolutional layer, a pooling layer, and a fully connected layer. Deep learning 16
  • 18. CNN ARCHITECTURE: TYPES OF LAYERS • Convolutional layer • a “filter” passes over the image, scanning a few pixels at a time and creating a feature map that predicts the class to which each feature belongs. • Pooling layer (downsampling) • reduces the amount of information in each feature obtained in the convolutional layer while maintaining the most important information . • there are usually several rounds of convolution and pooling. 2/25/2024 Deep learning 18
  • 19. CNN ARCHITECTURE: TYPES OF LAYERS • Fully connected input layer (flatten) • It takes the output of the previous layers, “flattens” them and turns them into a single vector that can be an input for the next stage. • The first fully connected layer takes the inputs from the feature analysis and applies weights to predict the correct label. • Fully connected output layer gives the final probabilities for each label. 2/25/2024 Deep learning 19
  • 21. CONVOLUTION OPERATION IS ELEMENT WISE MULTIPLY AND ADD Filter / Kernel
  • 22. PRODUCING FEATURE MAPS Original Sharpen Edge Detect “Strong” Edge Detect
  • 23. A SIMPLE PATTERN: EDGES HOW CAN WE DETECT EDGES WITH A KERNEL? Input 1 -1 Filter Output
  • 24. SIMPLE KERNELS / FILTERS
  • 25. X OR X? Image is represented as matrix of pixel values… and computers are literal! We want to be able to classify an X as an X even if it’s shifted, shrunk, rotated, deformed.
  • 26. CONVOLUTION PROCESS • Assume the filter/kernel is weight matrix wk . For example, lets assume a 3 x 3 weighted matrix. • The kernel is a filter to extract some particular features from the original images. • It could be for extracting curves , identifying a specific colour, or recognizing a particular voice. Deep learning 26
  • 27. CONVOLUTION OPERATION • Kernel/Filter, K = • 1 0 1 0 1 0 1 0 1 27
  • 28. PROCESS OF CONVOLUTION (CONTD.) 0 1 1 1 0 0 1 0 1 Input layer Filter/Kernel (Weighted matrix) 515 • For example, when the weighted matrix starts from the top left corner of the input layer, the output value is calculated as: (81x0+2x1+209x1)+(24x1+56x0+108X0)+(91x1+0x0+189x1) = 515 81 2 209 44 71 58 24 56 108 98 12 112 91 0 189 65 79 232 12 0 0 5 1 71 2 32 23 58 8 209 49 98 81 112 54 9 EXAMPLE • As the filter/kernel is slided across the input layer, the convolved layer is obtained by adding the values obtained by element wise multiplication of the weight matrix. Output
  • 29. PROCESS OF CONVOLUTION (CONTD.) 0 1 1 1 0 0 1 0 1 Input layer Filter/Kernel (Weighted matrix) Output (Activation/Feature Map) 515 374 • Dimension of output=n-f+1 • The distance between two consecutive receptive fields is called the stride. • In this example stride is 1 since the receptive field was moved by 1 pixel at a time. 81 2 209 44 71 58 24 56 108 98 12 112 91 0 189 65 79 232 12 0 0 5 1 71 2 32 23 58 8 209 49 98 81 112 54 9 EXAMPLE • The filter then moves by 1 pixel to the next receptive field and the process is repeated. The output layer obtained after the filter slides over the entire image would be a 4X4 matrix.This is called an activation map/ feature map.
  • 30. 30 Calculating output dimension of Convolution layer
  • 31. ReLU Layer 31 • ReLU stands for Rectified Linear Unit and is a non-linear operation. • ReLU is an element wise operation (applied per pixel) and replaces all negative pixel values in the feature map by zero. Output = Max(zero, Input)
  • 32. Pooling Layer (Sub-sampling or Down-sampling) • Pooling layer reduce the size of feature maps by using some functions to summarize sub- regions, such as taking the average or the maximum value
  • 33. FULLY CONNECTED LAYER After completion of series of convolutional, nonlinear and pooling layers, it is necessary to attach a fully connected layer. This layer takes the output information from convolutional networks. Attaching a fully connected layer to the end of the network results in an N dimensional vector, where N is the number of classes from which the model selects the desired class. 33 Deep learning
  • 36. CNNS FOR CLASSIFICATION • Train model with image data. • Learn weights of filters in convolutional layers. D tf.keras.activations. * tf.keras.layers.MaxPool2 D Convolution:Apply filters to generate feature maps. Non-linearity: Often ReLU. Pooling: Downsampling operation on each feature map. tf.keras.layers.Conv2
  • 37. CNNS FOR CLASSIFICATION: FEATURE LEARNING Learn features in input image through convolution Learn Introduce non-linearity through activation function (real-world data is non-linear!) Introduce Reduce dimensionality and preserve spatial invariance with pooling Reduce
  • 38. CNNS FOR CLASSIFICATION: CLASS PROBABILITIES CONV and POOL layers output high-level features of input Fully connected layer uses these features for classifying input image Express output as probability of image belonging to a particular class
  • 39. REPRESENTATION LEARNING IN DEEP CNNS Mid level features Low level features High level features Edges, dark spots Conv Layer 1 Eyes, ears,nose Conv Layer 2 Facial structure Conv Layer 3
  • 40. EXAMPLE – SIX CONVOLUTIONAL LAYERS
  • 41. CONVOLUTIONAL LAYERS: LOCAL CONNECTIVITY For a neuron in hidden layer: • Take inputs from patch • Compute weighted sum • Apply bias tf.keras.layers. Conv2D
  • 42. CONVOLUTIONAL LAYERS: LOCAL CONNECTIVITY For a neuron in hidden layer: • Take inputs from patch • Compute weighted sum • Apply bias 4x4 filter: matrix of weights wij for neuron (p,q) in hidden layer 1) applying a window of weights 2) computing linear combinations 3) activating with non-linear function tf.keras.layers.Conv2D
  • 43. OTHER ARCHITECTURES OFCNN LeNet-5 (1998) • AlexNet (2012) ZFNet (2013) GoogLeNet (2014) VGGNet(2014) ResNet (2015) • Over the years, many variants of this basic architecture have been developed such as: • These models can be used in applications by developers.