Caffe2 Quick Start Guide
eBook - ePub

Caffe2 Quick Start Guide

Modular and scalable deep learning made easy

Ashwin Nanjappa

  1. 136 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Caffe2 Quick Start Guide

Modular and scalable deep learning made easy

Ashwin Nanjappa

Book details
Book preview
Table of contents
Citations

About This Book

Build and train scalable neural network models on various platforms by leveraging the power of Caffe2

Key Features

  • Migrate models trained with other deep learning frameworks on Caffe2
  • Integrate Caffe2 with Android or iOS and implement deep learning models for mobile devices
  • Leverage the distributed capabilities of Caffe2 to build models that scale easily

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

  • Build and install Caffe2
  • Compose neural networks
  • Train neural network on CPU or GPU
  • Import a neural network from Caffe
  • Import deep learning models from other frameworks
  • Deploy models on CPU or GPU accelerators using inference engines
  • Deploy models at the edge and in the cloud

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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Caffe2 Quick Start Guide an online PDF/ePUB?
Yes, you can access Caffe2 Quick Start Guide by Ashwin Nanjappa in PDF and/or ePUB format, as well as other popular books in Informatica & Reti neurali. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781789138269
Edition
1
Subtopic
Reti neurali

Training Networks

In Chapter 2, Composing Networks, we learned how to create Caffe2 operators and how we can compose networks from them. In this chapter, the focus is on training neural networks. We will learn how to create a network that is intended for training and how to train it using Caffe2. We will continue to use the MNIST dataset as an example. However, instead of the MLP network we built in the previous chapter, we will create a popular network named LeNet.
This chapter will cover the following topics:
  • Introduction to training a neural network
  • Building the training network for LeNet
  • Training and monitoring the LeNet network

Introduction to training

In this section, we provide a brief overview of how a neural network is trained. This will help us to understand the later sections where we use Caffe2 to actually train a network.

Components of a neural network

We employ neural networks to solve a particular type of problem for which devising a computer algorithm would be onerous or difficult. For example, in the MNIST problem (introduced in Chapter 2, Composing Networks), handcrafting a complicated algorithm to detect the common stroke patterns for each digit, and thereby determining each digit, would be tedious. Instead, it is easier to design a neural network suited to this problem and then train it (as shown later in this chapter) using a lot of data to do the same. If the training data is diverse and the training is done carefully, such a network would also be far more robust to variations in the input data than any deterministic handcrafted algorithm would.
A neural network has two main components: its structure and its weights. We typically design the network structure and then use a training algorithm and training data to determine the weights. After it is trained, the network structure, with its embedded weights, can be used for inference on new unseen data, as shown in the following diagram:
Figure 3.1: Structure and weights of a network used for inference

Structure of a neural network

The structure of a network is the series of its layers, their types, and their configurations. The structure is typically devised by a researcher or a practitioner familiar with the problem that the neural network is being designed to solve. For example, to solve image classification problems, computer vision researchers might typically use a series of convolution layers in the network. (We will learn about the convolution layer later in this chapter.) Various configuration parameters of each layer also need to be determined beforehand, such as the size and number of the convolution filters in a convolution layer. There is a huge amount of interest in using deep learning itself to ascertain the structure of a network suited to a particular problem. However, discussion of this meta-learning topic is beyond the scope of this book.

Weights of a neural network

The second component of a network is its weights and biases. We generally refer to them together as weights, or sometimes as parameters. These are the floating point values that are the parameters of every layer in the network. How the weights of a layer are used is determined by the type of layer. For example, in a fully connected layer, a bigger weight value might signify a stronger correlation between an input signal and the network's output. In a convolution layer, the weights of a convolution filter might signify what type of pattern or shape in the input it is looking for.
In summary, we sit down and devise the structure of a network to solve a particular problem. Our choices in this process will be limited by our understanding of the problem space, the types of layers available in the DL framework, the hardware constraints of the accelerator we are using, and how much training time we are prepared to put up with. For example, the memory available in a GPU or CPU might limit the number of weights we might use in a layer or the number of layers we might use in the network. The amount of training time we are willing to spend also limits the number of weights and layers we can use in a network, because the more of these we employ, the longer it may take for the network to converge and train.

Training process

Once we have a network structure fleshed out, we can then use a DL framework such as Caffe2 to describe that structure. We then apply one of the many training algorithms available in the framework on our training data. This trains the network and learns the weights of the layers that would best amplify the signal and dampen the noise. This process is depicted in Figure 3.2:
Figure 3.2: Training is the process of learning the weights of a neural network using a training algorithm and data
Neural networks are typically trained using a gradient-based optimization algorithm. To do this, we first define an objective function or loss function for the network. This function computes a loss or error value by comparing the output of the network on a given input to the ground truth result of that input. The training process iteratively picks training data and computes its loss, and then uses the optimization algorithm to update the weights so that the error is reduced. This process is repeated until we see no further improvement in the accuracy of the network:
Figure 3.3: Three stages of an iteration in training
A single iteration of the training process is depicted in Figure 3.3. We can see that it has three distinct stages. The first stage is a Forward pass, where we essentially perform inference of the network with its current weights to obtain t...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Introduction and Installation
  7. Composing Networks
  8. Training Networks
  9. Working with Caffe
  10. Working with Other Frameworks
  11. Deploying Models to Accelerators for Inference
  12. Caffe2 at the Edge and in the cloud
  13. Other Books You May Enjoy
Citation styles for Caffe2 Quick Start Guide

APA 6 Citation

Nanjappa, A. (2019). Caffe2 Quick Start Guide (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/969852/caffe2-quick-start-guide-modular-and-scalable-deep-learning-made-easy-pdf (Original work published 2019)

Chicago Citation

Nanjappa, Ashwin. (2019) 2019. Caffe2 Quick Start Guide. 1st ed. Packt Publishing. https://www.perlego.com/book/969852/caffe2-quick-start-guide-modular-and-scalable-deep-learning-made-easy-pdf.

Harvard Citation

Nanjappa, A. (2019) Caffe2 Quick Start Guide. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/969852/caffe2-quick-start-guide-modular-and-scalable-deep-learning-made-easy-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Nanjappa, Ashwin. Caffe2 Quick Start Guide. 1st ed. Packt Publishing, 2019. Web. 14 Oct. 2022.