SlideShare a Scribd company logo
1 of 27
Download to read offline
Caffe Hands on tutorial – build, train & predict
MUHANAD SHAB KALEIA
Caffe
cooking recipe
Caffe for Deep Learning
Caffe
Train new model Pre-trained model
2
Caffe for Deep Learning
Installation

Caffe can be installed on both CPU only machine, or GPU
machine,

To install it step by step you can follow:
http://mohanadkaleia.com/install-caffe-on-ubuntu-with-no-gpu/
Caffe – Build Prediction Model
I. Design a network
II.Train the network
III.Predict new samples
4
Caffe – Build the Model
Build a network

Protobuff format: a data structure format that can be used by
Caffe to generate the code of the network

Python layers

C++ layers
Caffe – Build the Model
Data types supported by Caffe

Image Data – read raw images

Database – read data from LMDB*

HDF5

Memory Data
https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database 6
Caffe – Build the Model
Layers supported by Caffe

Inner Product

Convolution

Normalization Layers: LRN, MVNm Batch Normalization

Activation: ReLU, PreLU, Sigmoid, TanH, power, Exp, ...

Recurrent, LSTM

Loss layers: Softmax, Sum-of-Squares, Hinge, accuracy, ..

Utility layers: Split, Concat, Slice, Reshape, ...
Caffe – Build the Model
MNIST
Caffe – Build the Model
Protobuff – Convolutional layer
This slide borrowed from Kate Saenko UMASS Lowell
Caffe – Build the Model
Protobuff – Data layer
10
Caffe – Build the Model
2. Protobuff – Pooling layer
Layer definition
Layer parameters
Caffe – Build the Model
2. Protobuff – Fully Connected layer
Layer definition
Layer parameters
Learning rate
controlling
parameters
Caffe – Build the Model
2. Protobuff – ReLU Layer
Caffe – Build the Model
2. Protobuff – LOSS Layer
Takes labeled data
The output of
the last layer
Find the loss
for the back-prop
15
Caffe – Build the Model
2. Protobuff – graphical generator
16
●
The protobuff text can be converted into a graphical
form that represent the network using netscope:
http://ethereon.github.io/netscope/quickstart.html
●
If you are lazy enough try this one:
http://yanglei.me/gen_proto/
Caffe – Build the Model
Layers supported by Caffe
I. Design a network
II.Train the network
III.Predict new samples
17
Caffe – Train (Optimize) the net
Caffe Solver

AdaDelta

SGD

AdaGrad

Adam

RMSprop

Nesterov
Caffe – Train (Optimize) the net
Caffe Solver – configuration file
Caffe – Train (Optimize) the net
Caffe Solver – run the solver
caffe train -solver lenet_solver.prototxt
lenet_10000.caffemodel
lenet_10000.solverstate
20
Caffe – Train (Optimize) the net
Caffe Solver – run the solver
caffe train -solver lenet_solver.prototxt
Caffe – Build the Model
Layers supported by Caffe
I. Design a network
II.Train the network
III.Predict new samples
22
Caffe – Predict / Classify samples
Caffe Classifier
Caffe Classifier
Trained
model
Deploy.prototxt
Image
sample
Class
(output)
Parameters
Caffe – Predict / Classify samples
Caffe Classifier
img = cv2.imread(IMAGE_FILE,0)

Define the Classifier object:
net = caffe.Classifier(MODEL_FILE, PRETRAINED_MODEL, caffe.TEST)

Apply forward pass on the network:
res = net.forward(data = img)
24
Caffe – Predict / Classify samples
Caffe Classifier
By applying an image of number 9 as an example, the classifier was able
to classify it correctly as we can see from the image below:
Caffe – Hands on Tuturial
Step by step tutorial
The full details about this tutorial is available on my website:
http://mohanadkaleia.com/
Resources
[1] https://shadowthink.com/blog/tech/2016/08/28/Caffe-MNIST-tutorial
[2] http://caffe.berkeleyvision.org/gathered/examples/mnist.html
[3] http://shengshuyang.github.io/A-step-by-step-guide-to-Caffe.html
[4] https://software.intel.com/en-us/articles/training-and-deploying-deep-
learning-networks-with-caffe-optimized-for-intel-architecture#Training
[5] https://github.com/BVLC/caffe/wiki/Solver-Prototxt
[6] http://adilmoujahid.com/posts/2016/06/introduction-deep-learning-
python-caffe/
[7] http://stackoverflow.com/questions/33765029/caffe-how-to-predict-
from-a-pretrained-net
Resources
[8] https://github.com/9crk/caffe-mnist-test
[9] https://github.com/BVLC/caffe/wiki/Using-a-Trained-Network:-Deploy
[10] http://mohanadkaleia.com/install-caffe-on-ubuntu-with-no-gpu/
[11]
http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/01-
learning-lenet.ipynb
[12]https://docs.google.com/presentation/d/1UeKXVgRvvxg9OUdh_UiC5G
71UMscNPlvArsWER41PsU/edit#slide=id.gc2fcdcce7_216_278

More Related Content

What's hot

Machine learning with Apache Hama
Machine learning with Apache HamaMachine learning with Apache Hama
Machine learning with Apache Hama
Tommaso Teofili
 
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
Chris Fregly
 

What's hot (20)

Early Experiences with the OpenMP Accelerator Model
Early Experiences with the OpenMP Accelerator ModelEarly Experiences with the OpenMP Accelerator Model
Early Experiences with the OpenMP Accelerator Model
 
Apache HAMA: An Introduction toBulk Synchronization Parallel on Hadoop
Apache HAMA: An Introduction toBulk Synchronization Parallel on HadoopApache HAMA: An Introduction toBulk Synchronization Parallel on Hadoop
Apache HAMA: An Introduction toBulk Synchronization Parallel on Hadoop
 
Optimize Single Particle Orbital (SPO) Evaluations Based on B-splines
Optimize Single Particle Orbital (SPO) Evaluations Based on B-splinesOptimize Single Particle Orbital (SPO) Evaluations Based on B-splines
Optimize Single Particle Orbital (SPO) Evaluations Based on B-splines
 
Machine learning with Apache Hama
Machine learning with Apache HamaMachine learning with Apache Hama
Machine learning with Apache Hama
 
OpenCV DNN module vs. Ours method
OpenCV DNN module vs. Ours method OpenCV DNN module vs. Ours method
OpenCV DNN module vs. Ours method
 
Introduction to Polyaxon
Introduction to PolyaxonIntroduction to Polyaxon
Introduction to Polyaxon
 
Os Lamothe
Os LamotheOs Lamothe
Os Lamothe
 
TFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesTFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU Delegates
 
The Flow of TensorFlow
The Flow of TensorFlowThe Flow of TensorFlow
The Flow of TensorFlow
 
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
 
Concurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple SpacesConcurrent Programming with Ruby and Tuple Spaces
Concurrent Programming with Ruby and Tuple Spaces
 
Message-passing concurrency in Python
Message-passing concurrency in PythonMessage-passing concurrency in Python
Message-passing concurrency in Python
 
Scalable Hadoop with succinct Python: the best of both worlds
Scalable Hadoop with succinct Python: the best of both worldsScalable Hadoop with succinct Python: the best of both worlds
Scalable Hadoop with succinct Python: the best of both worlds
 
Notes from 2016 bay area deep learning school
Notes from 2016 bay area deep learning school Notes from 2016 bay area deep learning school
Notes from 2016 bay area deep learning school
 
Available HPC resources at CSUC
Available HPC resources at CSUCAvailable HPC resources at CSUC
Available HPC resources at CSUC
 
IS-ENES COMP Superscalar tutorial
IS-ENES COMP Superscalar tutorialIS-ENES COMP Superscalar tutorial
IS-ENES COMP Superscalar tutorial
 
Making fitting in RooFit faster
Making fitting in RooFit fasterMaking fitting in RooFit faster
Making fitting in RooFit faster
 
Analyzing ECP Proxy Apps with the Profiling Tool Score-P
Analyzing ECP Proxy Apps with the Profiling Tool Score-PAnalyzing ECP Proxy Apps with the Profiling Tool Score-P
Analyzing ECP Proxy Apps with the Profiling Tool Score-P
 
TinyML as-a-Service
TinyML as-a-ServiceTinyML as-a-Service
TinyML as-a-Service
 
DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depth
 

Similar to Caffe hands on tutorial

Similar to Caffe hands on tutorial (20)

Caffe2
Caffe2Caffe2
Caffe2
 
Deep learning - the conf br 2018
Deep learning - the conf br 2018Deep learning - the conf br 2018
Deep learning - the conf br 2018
 
Power-Efficient Programming Using Qualcomm Multicore Asynchronous Runtime Env...
Power-Efficient Programming Using Qualcomm Multicore Asynchronous Runtime Env...Power-Efficient Programming Using Qualcomm Multicore Asynchronous Runtime Env...
Power-Efficient Programming Using Qualcomm Multicore Asynchronous Runtime Env...
 
Developing MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack RoutersDeveloping MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack Routers
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with Nginx
 
IBM Cloud Paris Meetup - 20190520 - IA & Power
IBM Cloud Paris Meetup - 20190520 - IA & PowerIBM Cloud Paris Meetup - 20190520 - IA & Power
IBM Cloud Paris Meetup - 20190520 - IA & Power
 
Best Practices and Performance Studies for High-Performance Computing Clusters
Best Practices and Performance Studies for High-Performance Computing ClustersBest Practices and Performance Studies for High-Performance Computing Clusters
Best Practices and Performance Studies for High-Performance Computing Clusters
 
AWS (Hadoop) Meetup 30.04.09
AWS (Hadoop) Meetup 30.04.09AWS (Hadoop) Meetup 30.04.09
AWS (Hadoop) Meetup 30.04.09
 
Node-RED and Minecraft - CamJam September 2015
Node-RED and Minecraft - CamJam September 2015Node-RED and Minecraft - CamJam September 2015
Node-RED and Minecraft - CamJam September 2015
 
CaffeOnSpark: Deep Learning On Spark Cluster
CaffeOnSpark: Deep Learning On Spark ClusterCaffeOnSpark: Deep Learning On Spark Cluster
CaffeOnSpark: Deep Learning On Spark Cluster
 
Setting advanced PHP development environment
Setting advanced PHP development environmentSetting advanced PHP development environment
Setting advanced PHP development environment
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Serial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol
Serial Data from Arduino to Raspberry Pi to MySQL using CoAP ProtocolSerial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol
Serial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol
 
unga - boosting opensim
unga - boosting opensimunga - boosting opensim
unga - boosting opensim
 
An introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-REDAn introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-RED
 
Sundar Ranganathan, NetApp + Vinod Iyengar, H2O.ai - Driverless AI integratio...
Sundar Ranganathan, NetApp + Vinod Iyengar, H2O.ai - Driverless AI integratio...Sundar Ranganathan, NetApp + Vinod Iyengar, H2O.ai - Driverless AI integratio...
Sundar Ranganathan, NetApp + Vinod Iyengar, H2O.ai - Driverless AI integratio...
 
PowerAI Deep Dive ( key points )
PowerAI Deep Dive ( key points )PowerAI Deep Dive ( key points )
PowerAI Deep Dive ( key points )
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...
 

Recently uploaded

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 

Recently uploaded (20)

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 

Caffe hands on tutorial

  • 1. Caffe Hands on tutorial – build, train & predict MUHANAD SHAB KALEIA Caffe cooking recipe
  • 2. Caffe for Deep Learning Caffe Train new model Pre-trained model 2
  • 3. Caffe for Deep Learning Installation  Caffe can be installed on both CPU only machine, or GPU machine,  To install it step by step you can follow: http://mohanadkaleia.com/install-caffe-on-ubuntu-with-no-gpu/
  • 4. Caffe – Build Prediction Model I. Design a network II.Train the network III.Predict new samples 4
  • 5. Caffe – Build the Model Build a network  Protobuff format: a data structure format that can be used by Caffe to generate the code of the network  Python layers  C++ layers
  • 6. Caffe – Build the Model Data types supported by Caffe  Image Data – read raw images  Database – read data from LMDB*  HDF5  Memory Data https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database 6
  • 7. Caffe – Build the Model Layers supported by Caffe  Inner Product  Convolution  Normalization Layers: LRN, MVNm Batch Normalization  Activation: ReLU, PreLU, Sigmoid, TanH, power, Exp, ...  Recurrent, LSTM  Loss layers: Softmax, Sum-of-Squares, Hinge, accuracy, ..  Utility layers: Split, Concat, Slice, Reshape, ...
  • 8. Caffe – Build the Model MNIST
  • 9. Caffe – Build the Model Protobuff – Convolutional layer This slide borrowed from Kate Saenko UMASS Lowell
  • 10. Caffe – Build the Model Protobuff – Data layer 10
  • 11. Caffe – Build the Model 2. Protobuff – Pooling layer Layer definition Layer parameters
  • 12. Caffe – Build the Model 2. Protobuff – Fully Connected layer Layer definition Layer parameters Learning rate controlling parameters
  • 13. Caffe – Build the Model 2. Protobuff – ReLU Layer
  • 14. Caffe – Build the Model 2. Protobuff – LOSS Layer Takes labeled data The output of the last layer Find the loss for the back-prop 15
  • 15. Caffe – Build the Model 2. Protobuff – graphical generator 16 ● The protobuff text can be converted into a graphical form that represent the network using netscope: http://ethereon.github.io/netscope/quickstart.html ● If you are lazy enough try this one: http://yanglei.me/gen_proto/
  • 16. Caffe – Build the Model Layers supported by Caffe I. Design a network II.Train the network III.Predict new samples 17
  • 17. Caffe – Train (Optimize) the net Caffe Solver  AdaDelta  SGD  AdaGrad  Adam  RMSprop  Nesterov
  • 18. Caffe – Train (Optimize) the net Caffe Solver – configuration file
  • 19. Caffe – Train (Optimize) the net Caffe Solver – run the solver caffe train -solver lenet_solver.prototxt lenet_10000.caffemodel lenet_10000.solverstate 20
  • 20. Caffe – Train (Optimize) the net Caffe Solver – run the solver caffe train -solver lenet_solver.prototxt
  • 21. Caffe – Build the Model Layers supported by Caffe I. Design a network II.Train the network III.Predict new samples 22
  • 22. Caffe – Predict / Classify samples Caffe Classifier Caffe Classifier Trained model Deploy.prototxt Image sample Class (output) Parameters
  • 23. Caffe – Predict / Classify samples Caffe Classifier img = cv2.imread(IMAGE_FILE,0)  Define the Classifier object: net = caffe.Classifier(MODEL_FILE, PRETRAINED_MODEL, caffe.TEST)  Apply forward pass on the network: res = net.forward(data = img) 24
  • 24. Caffe – Predict / Classify samples Caffe Classifier By applying an image of number 9 as an example, the classifier was able to classify it correctly as we can see from the image below:
  • 25. Caffe – Hands on Tuturial Step by step tutorial The full details about this tutorial is available on my website: http://mohanadkaleia.com/
  • 26. Resources [1] https://shadowthink.com/blog/tech/2016/08/28/Caffe-MNIST-tutorial [2] http://caffe.berkeleyvision.org/gathered/examples/mnist.html [3] http://shengshuyang.github.io/A-step-by-step-guide-to-Caffe.html [4] https://software.intel.com/en-us/articles/training-and-deploying-deep- learning-networks-with-caffe-optimized-for-intel-architecture#Training [5] https://github.com/BVLC/caffe/wiki/Solver-Prototxt [6] http://adilmoujahid.com/posts/2016/06/introduction-deep-learning- python-caffe/ [7] http://stackoverflow.com/questions/33765029/caffe-how-to-predict- from-a-pretrained-net
  • 27. Resources [8] https://github.com/9crk/caffe-mnist-test [9] https://github.com/BVLC/caffe/wiki/Using-a-Trained-Network:-Deploy [10] http://mohanadkaleia.com/install-caffe-on-ubuntu-with-no-gpu/ [11] http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/01- learning-lenet.ipynb [12]https://docs.google.com/presentation/d/1UeKXVgRvvxg9OUdh_UiC5G 71UMscNPlvArsWER41PsU/edit#slide=id.gc2fcdcce7_216_278