SlideShare a Scribd company logo
1 of 33
Download to read offline
國立臺北護理健康大學 NTUNHS
Transfer Learning
Orozco Hsu
2022-04-11
1
About me
• Education
• NCU (MIS)、NCCU (CS)
• Work Experience
• Telecom big data Innovation
• AI projects
• Retail marketing technology
• User Group
• TW Spark User Group
• TW Hadoop User Group
• Taiwan Data Engineer Association Director
• Research
• Big Data/ ML/ AIOT/ AI Columnist
2
Tutorial
Content
3
Transfer Learning introduction
Homework
Keras pre-trained model
Transfer Learning with the ResNet50 Model
Code
• Download code
• https://github.com/orozcohsu/ntunhs_2022_01.git
• Folder/file
• 20220411_inter_master/run.ipynb
4
Code
5
Click button
Open it with Colab
Copy it to your
google drive
Check your google
drive
Keras pretrained model
6
Ref: https://www.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.html
Keras pre-trained model
• Keras Applications are deep learning models that are made available
alongside pre-trained weights
• These models can be used for prediction, feature extraction, and fine-
tuning
• Weights are downloaded automatically when instantiating a model.
They are stored at ~/.keras/models/
7
Keras pre-trained model
8
Ref: https://keras.io/api/applications/
More
• Keras offers two ways to build neural networks
• using Functional API
• It is more powerful than the sequential API in the sense branching or
sharing of layers is allowed here.
• It can have multiple inputs and outputs.
• using Sequential API
• Create the model layer-by-layer
• Sharing of layers or branching of layers is not allowed
• Can’t have multiple inputs or outputs
9
More
Using sequential API
10
Ref: https://www.analyticsvidhya.com/blog/2021/07/understanding-sequential-vs-functional-api-in-keras
More
Using functional API
11
More
12
tensorflow included keras library as a internal deep learning package
always check your tf version, especially in the CoLab
More
13
Exercise
• Try to run this code
14
pre-trained
Transfer Learning introduction
• Transfer Learning is a process where a model built for a problem is
again reused for another problem based on some factors
• Using Transfer Learning you can achieve good results if the data is
kind of similar to the data on which model is already trained
15
Transfer Learning introduction
• A CNN can be divided into two main parts
• Feature learning and classification
16
Ref: https://towardsdatascience.com/transfer-learning-with-vgg16-and-keras-50ea161580b4
17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Transfer Learning introduction
The VGG16 Model has 16 Convolutional and Max Pooling layers, 3 Dense layers
for the Fully-Connected layer, and an output layer of 1,000 classes
Ref: https://www.learndatasci.com/tutorials/hands-on-transfer-learning-keras/
Transfer Learning introduction
• Feature Extraction Approach (exclude top)
18
We will bootstrap a Fully-Connected layer to
generate predictions
top
Exercise
• Try to run this code
19
transfer_learning_mnist
training data
training data
Model Output
Output
fit
fit
Transfer Learning introduction
20
• Fine-Tuning Approach
the final convolutional and pooling layers are
unfrozen to allow training. A Fully-Connected
layer is defined for training and prediction.
Different Transfer Learning Strategies
• The training dataset is similar to the base training dataset and is small
in size
• Using a deep net-based ConvNet on such a dataset can result in overfitting of
the model
• The macro features of the pre-trained are likely to be important for this data
also as the data is alike to the base model data
• Freeze the weights of ConvNet and make them in use for extracting the
features
• Detach the fully connected layers from the pre-trained base ConvNet and add
new fully connected layers according to the number of classes in the target
dataset
21
ConvNet: Convolutional Neural Network
Different Transfer Learning Strategies
• The training dataset is similar to the base training dataset and is large
in size
• The data we have is large in nature so it is assumed that there won't be any
overfitting of the model here if the fine-tuning is performed in the whole full
network
• Detach the fully connected layers from the pre-trained base ConvNet and add
new fully connected layers according to the number of classes in the target
dataset
• Train the entire network
22
Exercise
• Try to run this code
23
fine_tuning
Layer1
Layer2
Layer3
…
Layer148
Layer149
Layer150
Layer151
Layer152
Layer153
Layer154
Set output as an input for next layer
New layer
Different Transfer Learning Strategies
• The target dataset is different from the base training dataset and is
small in nature
• Overfitting is again a concern in this type of situation where the data is small
• The higher-level features in ConvNet would not give any appropriate results
on the target dataset as the target dataset is not similar to the base dataset
24
Different Transfer Learning Strategies
• The target dataset is different from the base training dataset and is
large in nature
• We can train the ConvNet from scratch, due to the large size of the target
dataset and dissimilarity from the base dataset.
• It is good practice to initialize the weights from the pre-trained model and
fine-tune them that can result in the training faster
25
More
• Fast Style Transfer for Arbitrary Styles
• https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization
• https://deepai.org/machine-learning-model/fast-style-transfer
• https://www.youtube.com/watch?v=pLWIaQwkJwU
26
Transfer Learning with the ResNet50 Model
• It consists of 60,000 (size: 32x32) RGB color images in 10 classes
27
Ref: https://www.cs.toronto.edu/~kriz/cifar.html
Transfer Learning with the ResNet50 Model
• ResNet model of Computer Vision that is trained on the ImageNet
dataset having 14 million images that can be used for Image
classification tasks
• imagenet 1,000 class
• https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a
28
STAGE 1
STAGE 2
STAGE 3
STAGE 4
STAGE 0
INPUT
OUTPUT
ResNet50
CONV: 7× 7, 64, /2
BN, RELU
MAXPOOL: 3× 3, /2
STAGE 0
(3, 224, 224)
(64, 56, 56)
STAGE 1
BTNK1: 64, 56, 64, 1
(256, 56, 56)
BTNK2: 256, 56
(256, 56, 56)
BTNK2: 256, 56
(256, 56, 56)
STAGE 2
BTNK1: 256, 56, 128, 2
(512, 28, 28)
BTNK2: 512, 28
(512, 28, 28)
BTNK2: 512, 28
(512, 28, 28)
BTNK2: 512, 28
(512, 28, 28)
STAGE 3
BTNK1: 512, 28, 256, 2
(1024, 14, 14)
BTNK2: 1024, 14
(1024, 14, 14)
BTNK2: 1024, 14
(1024, 14, 14)
BTNK2: 1024, 14
(1024, 14, 14)
BTNK2: 1024, 14
(1024, 14, 14)
BTNK2: 1024, 14
(1024, 14, 14)
STAGE 4
BTNK1: 1024, 14, 512, 2
(2048, 7, 7)
BTNK2: 2048, 7
(2048, 7, 7)
BTNK2: 2048, 7
(2048, 7, 7)
BTNK1: C, W, C1, S
CONV: 1× 1, C1, /S
BN, RELU
CONV: 3× 3, C1, /1
BN, RELU
CONV: 1× 1, C1*4, /1
BN
CONV: 1× 1, C1*4, /S
BN
+, RELU
(C, W, W)
(C1*4, W/S, W/S)
BTNK2: C, W
CONV: 1× 1, C/4, /1
BN, RELU
CONV: 3× 3, C/4, /1
BN, RELU
CONV: 1× 1, C, /1
BN
+, RELU
(C, W, W)
(C, W, W)
More
30
Make sure GPU runtime
Change to High-RAM if available
More
31
Always check your resource if it hits the
maximum usage, it will reset runtime
Exercise
• Try to run this code
32
transfer_learning_resnet50
Homework
• Try to change other pre-trained models such like VGG16 or
InceptionV3 to rebuild the model and see how its
performance (reference page 14)
• https://www.tensorflow.org/api_docs/python/tf/keras/applications/
vgg16/VGG16
• Try to change other pre-trained models to rebuild a new
transfer learning model and see how its performance
• Or
• Change the trainable layers to compare its performance
(model fine tuning)
33

More Related Content

Similar to 3_Transfer_Learning.pdf

Modern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentationModern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentationGioele Ciaparrone
 
Entity embeddings for categorical data
Entity embeddings for categorical dataEntity embeddings for categorical data
Entity embeddings for categorical dataPaul Skeie
 
深度學習在AOI的應用
深度學習在AOI的應用深度學習在AOI的應用
深度學習在AOI的應用CHENHuiMei
 
ResNeSt: Split-Attention Networks
ResNeSt: Split-Attention NetworksResNeSt: Split-Attention Networks
ResNeSt: Split-Attention NetworksSeunghyun Hwang
 
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...Jinwon Lee
 
NVIDIA深度學習教育機構 (DLI): Object detection with jetson
NVIDIA深度學習教育機構 (DLI): Object detection with jetsonNVIDIA深度學習教育機構 (DLI): Object detection with jetson
NVIDIA深度學習教育機構 (DLI): Object detection with jetsonNVIDIA Taiwan
 
Bag of tricks for image classification with convolutional neural networks r...
Bag of tricks for image classification with convolutional neural networks   r...Bag of tricks for image classification with convolutional neural networks   r...
Bag of tricks for image classification with convolutional neural networks r...Dongmin Choi
 
NVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflow
NVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflowNVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflow
NVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflowNVIDIA Taiwan
 
Computer Vision for Beginners
Computer Vision for BeginnersComputer Vision for Beginners
Computer Vision for BeginnersSanghamitra Deb
 
Machine Learning, Deep Learning and Data Analysis Introduction
Machine Learning, Deep Learning and Data Analysis IntroductionMachine Learning, Deep Learning and Data Analysis Introduction
Machine Learning, Deep Learning and Data Analysis IntroductionTe-Yen Liu
 
NVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digits
NVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digitsNVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digits
NVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digitsNVIDIA Taiwan
 
Emerging Properties in Self-Supervised Vision Transformers
Emerging Properties in Self-Supervised Vision TransformersEmerging Properties in Self-Supervised Vision Transformers
Emerging Properties in Self-Supervised Vision TransformersSungchul Kim
 
Deep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep FeaturesDeep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep FeaturesTuri, Inc.
 
Training Neural Networks
Training Neural NetworksTraining Neural Networks
Training Neural NetworksDatabricks
 
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio..."Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...Edge AI and Vision Alliance
 
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Universitat Politècnica de Catalunya
 
Presentation vision transformersppt.pptx
Presentation vision transformersppt.pptxPresentation vision transformersppt.pptx
Presentation vision transformersppt.pptxhtn540
 
Deep learning with keras
Deep learning with kerasDeep learning with keras
Deep learning with kerasMOHITKUMAR1379
 
StackNet Meta-Modelling framework
StackNet Meta-Modelling frameworkStackNet Meta-Modelling framework
StackNet Meta-Modelling frameworkSri Ambati
 

Similar to 3_Transfer_Learning.pdf (20)

Modern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentationModern Convolutional Neural Network techniques for image segmentation
Modern Convolutional Neural Network techniques for image segmentation
 
Entity embeddings for categorical data
Entity embeddings for categorical dataEntity embeddings for categorical data
Entity embeddings for categorical data
 
深度學習在AOI的應用
深度學習在AOI的應用深度學習在AOI的應用
深度學習在AOI的應用
 
ResNeSt: Split-Attention Networks
ResNeSt: Split-Attention NetworksResNeSt: Split-Attention Networks
ResNeSt: Split-Attention Networks
 
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
 
NVIDIA深度學習教育機構 (DLI): Object detection with jetson
NVIDIA深度學習教育機構 (DLI): Object detection with jetsonNVIDIA深度學習教育機構 (DLI): Object detection with jetson
NVIDIA深度學習教育機構 (DLI): Object detection with jetson
 
Bag of tricks for image classification with convolutional neural networks r...
Bag of tricks for image classification with convolutional neural networks   r...Bag of tricks for image classification with convolutional neural networks   r...
Bag of tricks for image classification with convolutional neural networks r...
 
NVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflow
NVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflowNVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflow
NVIDIA 深度學習教育機構 (DLI): Image segmentation with tensorflow
 
Computer Vision for Beginners
Computer Vision for BeginnersComputer Vision for Beginners
Computer Vision for Beginners
 
Machine Learning, Deep Learning and Data Analysis Introduction
Machine Learning, Deep Learning and Data Analysis IntroductionMachine Learning, Deep Learning and Data Analysis Introduction
Machine Learning, Deep Learning and Data Analysis Introduction
 
NVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digits
NVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digitsNVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digits
NVIDIA 深度學習教育機構 (DLI): Medical image segmentation using digits
 
Emerging Properties in Self-Supervised Vision Transformers
Emerging Properties in Self-Supervised Vision TransformersEmerging Properties in Self-Supervised Vision Transformers
Emerging Properties in Self-Supervised Vision Transformers
 
Deep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep FeaturesDeep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep Features
 
Training Neural Networks
Training Neural NetworksTraining Neural Networks
Training Neural Networks
 
Deep Learning Initiative @ NECSTLab
Deep Learning Initiative @ NECSTLabDeep Learning Initiative @ NECSTLab
Deep Learning Initiative @ NECSTLab
 
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio..."Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
"Quantizing Deep Networks for Efficient Inference at the Edge," a Presentatio...
 
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
Training Deep Networks with Backprop (D1L4 Insight@DCU Machine Learning Works...
 
Presentation vision transformersppt.pptx
Presentation vision transformersppt.pptxPresentation vision transformersppt.pptx
Presentation vision transformersppt.pptx
 
Deep learning with keras
Deep learning with kerasDeep learning with keras
Deep learning with keras
 
StackNet Meta-Modelling framework
StackNet Meta-Modelling frameworkStackNet Meta-Modelling framework
StackNet Meta-Modelling framework
 

More from FEG

Sequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdfSequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdfFEG
 
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdfFEG
 
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdfFEG
 
Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318FEG
 
2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practices2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practicesFEG
 
2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratch2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratchFEG
 
2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratch2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratchFEG
 
2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratch2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratchFEG
 
2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_RulesFEG
 
202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)FEG
 
202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis Visualization202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis VisualizationFEG
 
Image Classification (20230411)
Image Classification (20230411)Image Classification (20230411)
Image Classification (20230411)FEG
 
Google CoLab (20230321)
Google CoLab (20230321)Google CoLab (20230321)
Google CoLab (20230321)FEG
 
Supervised Learning
Supervised LearningSupervised Learning
Supervised LearningFEG
 
UnSupervised Learning Clustering
UnSupervised Learning ClusteringUnSupervised Learning Clustering
UnSupervised Learning ClusteringFEG
 
Data Visualization in Excel
Data Visualization in ExcelData Visualization in Excel
Data Visualization in ExcelFEG
 
6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdf6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdfFEG
 
5_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.pdf5_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.pdfFEG
 
4_Regression_analysis.pdf
4_Regression_analysis.pdf4_Regression_analysis.pdf
4_Regression_analysis.pdfFEG
 
3_Decision_tree.pdf
3_Decision_tree.pdf3_Decision_tree.pdf
3_Decision_tree.pdfFEG
 

More from FEG (20)

Sequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdfSequence Model pytorch at colab with gpu.pdf
Sequence Model pytorch at colab with gpu.pdf
 
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
學院碩士班_非監督式學習_使用Orange3直接使用_分群_20240417.pdf
 
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
資料視覺化_透過Orange3進行_無須寫程式直接使用_碩士學程_202403.pdf
 
Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318Pytorch cnn netowork introduction 20240318
Pytorch cnn netowork introduction 20240318
 
2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practices2023 Decision Tree analysis in business practices
2023 Decision Tree analysis in business practices
 
2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratch2023 Clustering analysis using Python from scratch
2023 Clustering analysis using Python from scratch
 
2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratch2023 Data visualization using Python from scratch
2023 Data visualization using Python from scratch
 
2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratch2023 Supervised Learning for Orange3 from scratch
2023 Supervised Learning for Orange3 from scratch
 
2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules
 
202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)202312 Exploration Data Analysis Visualization (English version)
202312 Exploration Data Analysis Visualization (English version)
 
202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis Visualization202312 Exploration of Data Analysis Visualization
202312 Exploration of Data Analysis Visualization
 
Image Classification (20230411)
Image Classification (20230411)Image Classification (20230411)
Image Classification (20230411)
 
Google CoLab (20230321)
Google CoLab (20230321)Google CoLab (20230321)
Google CoLab (20230321)
 
Supervised Learning
Supervised LearningSupervised Learning
Supervised Learning
 
UnSupervised Learning Clustering
UnSupervised Learning ClusteringUnSupervised Learning Clustering
UnSupervised Learning Clustering
 
Data Visualization in Excel
Data Visualization in ExcelData Visualization in Excel
Data Visualization in Excel
 
6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdf6_Association_rule_碩士班第六次.pdf
6_Association_rule_碩士班第六次.pdf
 
5_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.pdf5_Neural_network_碩士班第五次.pdf
5_Neural_network_碩士班第五次.pdf
 
4_Regression_analysis.pdf
4_Regression_analysis.pdf4_Regression_analysis.pdf
4_Regression_analysis.pdf
 
3_Decision_tree.pdf
3_Decision_tree.pdf3_Decision_tree.pdf
3_Decision_tree.pdf
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

3_Transfer_Learning.pdf

  • 2. About me • Education • NCU (MIS)、NCCU (CS) • Work Experience • Telecom big data Innovation • AI projects • Retail marketing technology • User Group • TW Spark User Group • TW Hadoop User Group • Taiwan Data Engineer Association Director • Research • Big Data/ ML/ AIOT/ AI Columnist 2
  • 3. Tutorial Content 3 Transfer Learning introduction Homework Keras pre-trained model Transfer Learning with the ResNet50 Model
  • 4. Code • Download code • https://github.com/orozcohsu/ntunhs_2022_01.git • Folder/file • 20220411_inter_master/run.ipynb 4
  • 5. Code 5 Click button Open it with Colab Copy it to your google drive Check your google drive
  • 6. Keras pretrained model 6 Ref: https://www.mathworks.com/help/deeplearning/ug/pretrained-convolutional-neural-networks.html
  • 7. Keras pre-trained model • Keras Applications are deep learning models that are made available alongside pre-trained weights • These models can be used for prediction, feature extraction, and fine- tuning • Weights are downloaded automatically when instantiating a model. They are stored at ~/.keras/models/ 7
  • 8. Keras pre-trained model 8 Ref: https://keras.io/api/applications/
  • 9. More • Keras offers two ways to build neural networks • using Functional API • It is more powerful than the sequential API in the sense branching or sharing of layers is allowed here. • It can have multiple inputs and outputs. • using Sequential API • Create the model layer-by-layer • Sharing of layers or branching of layers is not allowed • Can’t have multiple inputs or outputs 9
  • 10. More Using sequential API 10 Ref: https://www.analyticsvidhya.com/blog/2021/07/understanding-sequential-vs-functional-api-in-keras
  • 12. More 12 tensorflow included keras library as a internal deep learning package always check your tf version, especially in the CoLab
  • 14. Exercise • Try to run this code 14 pre-trained
  • 15. Transfer Learning introduction • Transfer Learning is a process where a model built for a problem is again reused for another problem based on some factors • Using Transfer Learning you can achieve good results if the data is kind of similar to the data on which model is already trained 15
  • 16. Transfer Learning introduction • A CNN can be divided into two main parts • Feature learning and classification 16 Ref: https://towardsdatascience.com/transfer-learning-with-vgg16-and-keras-50ea161580b4
  • 17. 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Transfer Learning introduction The VGG16 Model has 16 Convolutional and Max Pooling layers, 3 Dense layers for the Fully-Connected layer, and an output layer of 1,000 classes Ref: https://www.learndatasci.com/tutorials/hands-on-transfer-learning-keras/
  • 18. Transfer Learning introduction • Feature Extraction Approach (exclude top) 18 We will bootstrap a Fully-Connected layer to generate predictions top
  • 19. Exercise • Try to run this code 19 transfer_learning_mnist training data training data Model Output Output fit fit
  • 20. Transfer Learning introduction 20 • Fine-Tuning Approach the final convolutional and pooling layers are unfrozen to allow training. A Fully-Connected layer is defined for training and prediction.
  • 21. Different Transfer Learning Strategies • The training dataset is similar to the base training dataset and is small in size • Using a deep net-based ConvNet on such a dataset can result in overfitting of the model • The macro features of the pre-trained are likely to be important for this data also as the data is alike to the base model data • Freeze the weights of ConvNet and make them in use for extracting the features • Detach the fully connected layers from the pre-trained base ConvNet and add new fully connected layers according to the number of classes in the target dataset 21 ConvNet: Convolutional Neural Network
  • 22. Different Transfer Learning Strategies • The training dataset is similar to the base training dataset and is large in size • The data we have is large in nature so it is assumed that there won't be any overfitting of the model here if the fine-tuning is performed in the whole full network • Detach the fully connected layers from the pre-trained base ConvNet and add new fully connected layers according to the number of classes in the target dataset • Train the entire network 22
  • 23. Exercise • Try to run this code 23 fine_tuning Layer1 Layer2 Layer3 … Layer148 Layer149 Layer150 Layer151 Layer152 Layer153 Layer154 Set output as an input for next layer New layer
  • 24. Different Transfer Learning Strategies • The target dataset is different from the base training dataset and is small in nature • Overfitting is again a concern in this type of situation where the data is small • The higher-level features in ConvNet would not give any appropriate results on the target dataset as the target dataset is not similar to the base dataset 24
  • 25. Different Transfer Learning Strategies • The target dataset is different from the base training dataset and is large in nature • We can train the ConvNet from scratch, due to the large size of the target dataset and dissimilarity from the base dataset. • It is good practice to initialize the weights from the pre-trained model and fine-tune them that can result in the training faster 25
  • 26. More • Fast Style Transfer for Arbitrary Styles • https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization • https://deepai.org/machine-learning-model/fast-style-transfer • https://www.youtube.com/watch?v=pLWIaQwkJwU 26
  • 27. Transfer Learning with the ResNet50 Model • It consists of 60,000 (size: 32x32) RGB color images in 10 classes 27 Ref: https://www.cs.toronto.edu/~kriz/cifar.html
  • 28. Transfer Learning with the ResNet50 Model • ResNet model of Computer Vision that is trained on the ImageNet dataset having 14 million images that can be used for Image classification tasks • imagenet 1,000 class • https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a 28
  • 29. STAGE 1 STAGE 2 STAGE 3 STAGE 4 STAGE 0 INPUT OUTPUT ResNet50 CONV: 7× 7, 64, /2 BN, RELU MAXPOOL: 3× 3, /2 STAGE 0 (3, 224, 224) (64, 56, 56) STAGE 1 BTNK1: 64, 56, 64, 1 (256, 56, 56) BTNK2: 256, 56 (256, 56, 56) BTNK2: 256, 56 (256, 56, 56) STAGE 2 BTNK1: 256, 56, 128, 2 (512, 28, 28) BTNK2: 512, 28 (512, 28, 28) BTNK2: 512, 28 (512, 28, 28) BTNK2: 512, 28 (512, 28, 28) STAGE 3 BTNK1: 512, 28, 256, 2 (1024, 14, 14) BTNK2: 1024, 14 (1024, 14, 14) BTNK2: 1024, 14 (1024, 14, 14) BTNK2: 1024, 14 (1024, 14, 14) BTNK2: 1024, 14 (1024, 14, 14) BTNK2: 1024, 14 (1024, 14, 14) STAGE 4 BTNK1: 1024, 14, 512, 2 (2048, 7, 7) BTNK2: 2048, 7 (2048, 7, 7) BTNK2: 2048, 7 (2048, 7, 7) BTNK1: C, W, C1, S CONV: 1× 1, C1, /S BN, RELU CONV: 3× 3, C1, /1 BN, RELU CONV: 1× 1, C1*4, /1 BN CONV: 1× 1, C1*4, /S BN +, RELU (C, W, W) (C1*4, W/S, W/S) BTNK2: C, W CONV: 1× 1, C/4, /1 BN, RELU CONV: 3× 3, C/4, /1 BN, RELU CONV: 1× 1, C, /1 BN +, RELU (C, W, W) (C, W, W)
  • 30. More 30 Make sure GPU runtime Change to High-RAM if available
  • 31. More 31 Always check your resource if it hits the maximum usage, it will reset runtime
  • 32. Exercise • Try to run this code 32 transfer_learning_resnet50
  • 33. Homework • Try to change other pre-trained models such like VGG16 or InceptionV3 to rebuild the model and see how its performance (reference page 14) • https://www.tensorflow.org/api_docs/python/tf/keras/applications/ vgg16/VGG16 • Try to change other pre-trained models to rebuild a new transfer learning model and see how its performance • Or • Change the trainable layers to compare its performance (model fine tuning) 33