Home Data Deep Learning with R Cookbook

Deep Learning with R Cookbook

By Swarna Gupta , Rehan Ali Ansari , Dipayan Sarkar
books-svg-icon Book
eBook $35.99 $24.99
Print $48.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $35.99 $24.99
Print $48.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Working with Convolutional Neural Networks
About this book
Deep learning (DL) has evolved in recent years with developments such as generative adversarial networks (GANs), variational autoencoders (VAEs), and deep reinforcement learning. This book will get you up and running with R 3.5.x to help you implement DL techniques. The book starts with the various DL techniques that you can implement in your apps. A unique set of recipes will help you solve binomial and multinomial classification problems, and perform regression and hyperparameter optimization. To help you gain hands-on experience of concepts, the book features recipes for implementing convolutional neural networks (CNNs), recurrent neural networks (RNNs), and Long short-term memory (LSTMs) networks, as well as sequence-to-sequence models and reinforcement learning. You’ll then learn about high-performance computation using GPUs, along with learning about parallel computation capabilities in R. Later, you’ll explore libraries, such as MXNet, that are designed for GPU computing and state-of-the-art DL. Finally, you’ll discover how to solve different problems in NLP, object detection, and action identification, before understanding how to use pre-trained models in DL apps. By the end of this book, you’ll have comprehensive knowledge of DL and DL packages, and be able to develop effective solutions for different DL problems.
Publication date:
February 2020
Publisher
Packt
Pages
328
ISBN
9781789805673

 

Working with Convolutional Neural Networks

Convolutional Neural Networks (CNNs) are the most popular and widely used deep neural networks for computer vision problems. They are used in a variety of applications including image classification, face recognition, document analysis, medical image analysis, action recognition, and natural language processing. In this chapter, we will focus on learning convolutional operations, and concepts such as padding and strides, to optimize CNNs. The idea behind this chapter is to make you well versed with the functioning of the CNN and learn techniques such as data augmentation and batch normalization to fine-tune your network and prevent overfitting. We will also provide a brief discussion about how we can leverage transfer learning to boost model performance. 

In this chapter, we will cover the following recipes:

    ...
 

Introduction to convolutional operations

The generic architecture of CNN is comprised of convolutional layers followed by fully connected layers. Like other neural networks, a CNN also contains input, hidden and output layers, but it works by restructuring the data into tensors that consist of the image, and the width and height of the image. In CNN, each volume in one layer is connected only to a spatially relevant region in the next layer to ensure that when the number of layers increases, each neuron has a local influence on its specific location. A CNN may also contain pooling layers along with few fully connected layers.

The following is an example of a simple CNN with convolution and pooling layers. In this recipe, we will work with convolution layers. We will introduce the concept of pooling layers in the Getting familiar with pooling layers recipe of...

 

Understanding strides and padding

In this recipe, we will learn about two key configuration hyperparameters of CNN, which are strides and padding. Strides are used mainly to reduce the size of the output volume. Padding is another technique that lets us preserve the dimensions of the input volume in the output volume, thus enabling us to extract the low-level features efficiently.

Strides: Stride, in very simple terms, means the step of the convolution operation. Stride specifies the amount by which filters convolve around the input. For example, if we specify the value of stride argument as 1, that means the filter will shift one unit at a time over the input matrix. 

Strides can be used for multiple purposes, primarily the following:

  • To avoid feature overlapping
  • To achieve smaller spatial dimensionality of the output volume

In the following diagram, you...

 

Getting familiar with pooling layers

CNNs use pooling layers to reduce the size of the representation, to speed up the computation of the network, and to ensure robust feature extraction. The pooling layer is mostly stacked on top of the convolutional layer and this layer heavily downsizes the input dimension to reduce the computation in the network and also reduce overfitting.

There are two most commonly used types of pooling techniques :

  • Max pooling: This type of pooling does downsampling by dividing the input matrix into pooling regions followed by computing the max values of each region.

Here's an example:

  • Average poolingThis type of pooling does downsampling by dividing the input matrix into pooling regions followed by computing the average values of each region. 

Here's an example:

In this recipe, we will learn how...

 

Implementing transfer learning

Transfer learning helps us solve a new problem using fewer examples by using information gained from solving other related tasks. It is a technique where we reuse a learned model trained on a different dataset to solve a similar but different problem. In transfer learning, we extend the learning of a pre-trained model in our network and build a new model to solve a new learning problem. The keras library in R provides many pre-trained models; we will be using one such model called as VGG16 to train our network.

Getting ready

We will start by importing the keras library into our environment:

library(keras)

In this example, we will work with a subset of the Dogs versus Cats dataset from...

About the Authors
  • Swarna Gupta

    Swarna Gupta holds a B.E. in computer science and has 6 years of experience in the data science space. She is currently working with Rolls Royce in the capacity of a data scientist. Her work revolves around leveraging data science and machine learning to create value for the business. She has extensively worked on IoT-based projects in the vehicle telematics and solar manufacturing industries.During her current association with Rolls Royce she worked in various deep learning techniques and solutions to solve fleet issues in aerospace domain. She also manages time from her busy schedule to be a regular pro-bono contributor to social organizations, helping them to solve specific business problems with the help of data science and machine learning.

    Browse publications by this author
  • Rehan Ali Ansari

    Rehan has a bachelors in Electrical and Electronics engineering with 5 years of experience in data science and machine learning field. He is currently associated with the digital competency at AP Moller Maersk Group in the capacity of a data scientist. He has a diverse background of working in multiple domains like fashion retail, IoT, renewable energy sector and trade finance. He is a strong believer of agile way of developing data driven machine learning and AI products. Out of his busy schedule he manages to explore new areas in the field of AI and robotics.

    Browse publications by this author
  • Dipayan Sarkar

    Dipayan Sarkar holds a Masters in Economics and comes with 17+ years of experience. Dipayan has won international challenges in predictive modeling and takes a keen interest in the mathematics behind machine learning techniques. Before opting to become an independent consultant and a mentor in the data science and machine learning space with various organizations and educational institutions, he had served in the capacity of a senior data scientist with Fortune 500 companies in the US and Europe. He is currently associated with Great Lakes Institute of Management as a visiting faculty (Analytics) and BML Munjal University as an adjunct faculty (Analytics and Machine Learning). He has co-authored a book on "Ensemble Machine Learning with Python" with PACKT Publishing.

    Browse publications by this author
Deep Learning with R Cookbook
Unlock this book and the full library FREE for 7 days
Start now