23,92 €
Build and train scalable neural network models on various platforms by leveraging the power of Caffe2
Key Features
Book Description
Caffe2 is a popular deep learning library used for fast and scalable training and inference of deep learning models on various platforms. This book introduces you to the Caffe2 framework and shows how you can leverage its power to build, train, and deploy efficient neural network models at scale.
It will cover the topics of installing Caffe2, composing networks using its operators, training models, and deploying models to different architectures. It will also show how to import models from Caffe and from other frameworks using the ONNX interchange format. It covers the topic of deep learning accelerators such as CPU and GPU and shows how to deploy Caffe2 models for inference on accelerators using inference engines. Caffe2 is built for deployment to a diverse set of hardware, using containers on the cloud and resource constrained hardware such as Raspberry Pi, which will be demonstrated.
By the end of this book, you will be able to not only compose and train popular neural network models with Caffe2, but also be able to deploy them on accelerators, to the cloud and on resource constrained platforms such as mobile and embedded hardware.
What you will learn
Who this book is for
Data scientists and machine learning engineers who wish to create fast and scalable deep learning models in Caffe2 will find this book to be very useful. Some understanding of the basic machine learning concepts and prior exposure to programming languages like C++ and Python will be useful.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 148
Veröffentlichungsjahr: 2019
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor:Amey VarangaonkarAcquisition Editor:Siddharth MandalContent Development Editor:Mohammed Yusuf ImaratwaleTechnical Editor: Rutuja VazeCopy Editor: Safis EditingProject Coordinator:Kinjal BariProofreader: Safis EditingIndexer: Pratik ShirodkarGraphics:Jason MonteiroProduction Coordinator:Jyoti Chauhan
First published: May 2019
Production reference: 1310519
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78913-775-0
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Ashwin Nanjappa is a senior architect at NVIDIA, working in the TensorRT team on improving deep learning inference on GPU accelerators. He has a PhD from the National University of Singapore in developing GPU algorithms for the fundamental computational geometry problem of 3D Delaunay triangulation. As a post-doctoral research fellow at the BioInformatics Institute (Singapore), he developed GPU-accelerated machine learning algorithms for pose estimation using depth cameras. As an algorithms research engineer at Visenze (Singapore), he implemented computer vision algorithm pipelines in C++, developed a training framework built upon Caffe in Python, and trained deep learning models for some of the world's most popular online shopping portals.
Gianni Rosa Gallina is an Italian senior software engineer and architect who has been focused on emerging technologies, AI, and virtual/augmented reality since 2013. Currently, he works in Deltatre's Innovation Lab, prototyping solutions for next-generation sport experiences and business services. Besides that, he has 10+ years of certified experience as consultant on Microsoft and .NET technologies (including technologies such as the Internet of Things, the cloud, and desktop/mobile apps). Since 2011, he has been awarded Microsoft MVP in the Windows Development category. He has been a Pluralsight Author since 2013 and is a speaker at national and international conferences.
Ryan Riley has been in the futures and derivatives industry for almost 20 years. He received bachelor's and master's degrees from DePaul University in applied statistics. Doing his coursework in math meant he had to teach himself how to program, thus forcing him to read more technical books on programming than someone would otherwise. Ryan has worked with numerous AI libraries in various languages and is currently using the Caffe2 C++ library to develop and implement futures and derivatives trading strategies at PNT Financial.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Caffe2 Quick Start Guide
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Introduction and Installation
Introduction to deep learning
AI
ML
Deep learning
Introduction to Caffe2
Caffe2 and PyTorch
Hardware requirements
Software requirements
Building and installing Caffe2
Installing dependencies
Installing acceleration libraries
Building Caffe2
Installing Caffe2
Testing the Caffe2 Python API
Testing the Caffe2 C++ API
Summary
Composing Networks
Operators
Example – the MatMul operator
Difference between layers and operators
Example – a fully connected operator
Building a computation graph
Initializing Caffe2
Composing the model network
Sigmoid operator
Softmax operator
Adding input blobs to the workspace
Running the network
Building a multilayer perceptron neural network
MNIST problem
Building a MNIST MLP network
Initializing global constants
Composing network layers
ReLU layer
Set weights of network layers
Running the network
Summary
Training Networks
Introduction to training
Components of a neural network
Structure of a neural network
Weights of a neural network
Training process
Gradient descent variants
LeNet network
Convolution layer
Pooling layer
Training data
Building LeNet
Layer 1 – Convolution
Layer 2 – Max-pooling
Layers 3 and 4 – Convolution and max-pooling
Layers 5 and 6 – Fully connected and ReLU
Layer 7 and 8 – Fully connected and Softmax
Training layers
Loss layer
Optimization layers
Accuracy layer
Training and monitoring
Summary
Working with Caffe
The relationship between Caffe and Caffe2
Introduction to AlexNet
Building and installing Caffe
Installing Caffe prerequisites
Building Caffe
Caffe model file formats
Prototxt file
Caffemodel file
Downloading Caffe model files
Caffe2 model file formats
predict_net file
init_net file
Converting a Caffe model to Caffe2
Converting a Caffe2 model to Caffe
Summary
Working with Other Frameworks
Open Neural Network Exchange
Installing ONNX
ONNX format
ONNX IR
ONNX operators
ONNX in Caffe2
Exporting the Caffe2 model to ONNX
Using the ONNX model in Caffe2
Visualizing the ONNX model
Summary
Deploying Models to Accelerators for Inference
Inference engines
NVIDIA TensorRT
Installing TensorRT
Using TensorRT
Importing a pre-trained network or creating a network
Building an optimized engine from the network
Inference using execution context of an engine
TensorRT API and usage
Intel OpenVINO
Installing OpenVINO
Model conversion
Model inference
Summary
Caffe2 at the Edge and in the cloud
Caffe2 at the edge on Raspberry Pi
Raspberry Pi
Installing Raspbian
Building Caffe2 on Raspbian
Caffe2 in the cloud using containers
Installing Docker
Installing nvidia-docker
Running Caffe2 containers
Caffe2 model visualization
Visualization using Caffe2 net_drawer
Visualization using Netron
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
Caffe2 is a popular deep learning framework designed with a focus on scalability, high performance, and portability. Written in C++, it has both a C++ API and a Python API. This book is a guide for you to quickly get started with Caffe2. It will cover the topics of installing Caffe2, composing networks using its operators, training models, and deploying models to inference engines, devices at the edge, and the cloud. It will also show you how to work with Caffe2 and other deep learning frameworks using the ONNX interchange format.
Data scientists and machine learning engineers who wish to create fast and scalable deep learning models in Caffe2 will find this book to be very useful.
Chapter 1, Introduction and Installation, introduces Caffe2 and examines how to build and install it.
Chapter 2, Composing Networks, teaches you about Caffe2 operators and how to compose them to build a simple computation graph and a neural network to recognize handwritten digits.
Chapter 3, Training Networks, gets into how to use Caffe2 to compose a network for training and how to train a network to solve the MNIST problem.
Chapter 4, Working with Caffe, explores the relationship between Caffe and Caffe2 and how to work with models trained in Caffe.
Chapter 5, Working with Other Frameworks, looks at contemporary deep learning frameworks such as TensorFlow and PyTorch and how we can exchange models from and to Caffe2 and these other frameworks.
Chapter 6, Deploying Models to Accelerators for Inference, talks about inference engines and how they are an essential tool for the final deployment of a trained Caffe2 model on accelerators. We focus on two types of popular accelerators: NVIDIA GPUs and Intel CPUs. We look at how to install and use TensorRT for deploying our Caffe2 model on NVIDIA GPUs. We also look at the installation and use of OpenVINO for deploying our Caffe2 model on Intel CPUs and accelerators.
Chapter 7, Caffe2 at the Edge and in the cloud, covers two applications of Caffe2 to demonstrate its ability to scale. As an application of Caffe2 with edge devices, we look at how to build Caffe2 on Raspberry Pi single-board computers and how to run Caffe2 applications on them. As an application of Caffe2 with the cloud, we look at the use of Caffe2 in Docker containers.
Some understanding of basic machine learning concepts and prior exposure to programming languages such as C++ and Python will be useful.
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packt.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Caffe2-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.
Welcome to the Caffe2 Quick Start Guide. This book aims to provide you with a quick introduction to the Caffe2 deep learning framework and how to use it for training and deployment of deep learning models. This book uses code samples to create, train, and run inference on actual deep learning models that solve real problems. In this way, its code can be applied quickly by readers to their own applications.
This chapter provides a brief introduction to Caffe2 and shows you how to build and install it on your computer. In this chapter, we will cover the following topics:
Introduction to deep learning and Caffe2
Building and installing Caffe2
Testing Caffe2 Python API
Testing Caffe2 C++ API
Terms such as artificial intelligence (AI), machine learning (ML), and deep learning (DL) are popular right now. This popularity can be attributed to significant improvements that deep learning techniques have brought about in the last few years in enabling computers to see, hear, read, and create. First and foremost, we'll introduce these three fields and how they intersect:
Artificial intelligence (AI) is a general term used to refer to the intelligence of computers, specifically their ability to reason, sense, perceive, and respond. It is used to refer to any non-biological system that has intelligence, and this intelligence is a consequence of a set of rules. It does not matter in AI if those sets of rules were created manually by a human, or if those rules were automatically learned by a computer by analyzing data. Research into AI started in 1956, and it has been through many ups and a couple of downs, called AI winters, since then.
Machine learning (ML) is a subset of AI that uses statistics, data, and learning algorithms to teach computers to learn from given data. This data, called training data, is specific to the problem being solved, and contains examples of input and the expected output for each input. ML algorithms learn models or representations automatically from training data, and these models can be used to obtain predictions for new input data.
There are many popular types of models in ML, including artificial neural networks (ANNs), Bayesian networks, support vector machines (SVM), and random forests. The ML model that is of interest to us in this book is ANN. The structure of ANNs are inspired by the connections in the brain. These neural network models were initially popular in ML, but later fell out of favor since they required enormous computing power that was not available at that time.
Over the last decade, utilization of the parallel processing capability of graphics processing units (GPUs) to solve general computation problems became popular. This type of computation came to be known as general-purpose computing on GPU (GPGPU). GPUs were quite affordable and were easy to use as accelerators by using GPGPU programming models and APIs such as
