Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Deep Learning with R Cookbook

You're reading from   Deep Learning with R Cookbook Over 45 unique recipes to delve into neural network techniques using R 3.5.x

Arrow left icon
Product type Paperback
Published in Feb 2020
Publisher Packt
ISBN-13 9781789805673
Length 328 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Swarna Gupta Swarna Gupta
Author Profile Icon Swarna Gupta
Swarna Gupta
Rehan Ali Ansari Rehan Ali Ansari
Author Profile Icon Rehan Ali Ansari
Rehan Ali Ansari
Dipayan Sarkar Dipayan Sarkar
Author Profile Icon Dipayan Sarkar
Dipayan Sarkar
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Understanding Neural Networks and Deep Neural Networks 2. Working with Convolutional Neural Networks FREE CHAPTER 3. Recurrent Neural Networks in Action 4. Implementing Autoencoders with Keras 5. Deep Generative Models 6. Handling Big Data Using Large-Scale Deep Learning 7. Working with Text and Audio for NLP 8. Deep Learning for Computer Vision 9. Implementing Reinforcement Learning 10. Other Books You May Enjoy

Setting up the environment

Before implementing a deep neural network, we need to set up our system and configure it so that we can apply a variety of deep learning techniques. This recipe assumes that you have the Anaconda distribution installed on your system.

Getting ready 

Let's configure our system for deep learning. It is recommended that you create a deep learning environment in Anaconda. If you have an older version of R in the conda environment, you need to update your R version to 3.5.x or above.

You also need to install the CUDA and cuDNN libraries for GPU support. You can read more about the prerequisites at https://tensorflow.rstudio.com/tools/local_gpu.html#prerequisties.

Please note that if your system does not have NVIDIA graphics support, then GPU processing cannot be done.

How to do it...

Let's create an environment in Anaconda (ensure that you have R and Python installed):

  1. Go to Anaconda Navigator from the Start menu.
  2. Click on Environments.
  3. Create a new environment and name it. Make sure that both the Python and R options are selected, as shown in the following screenshot:

  1. Install the keras library in R using the following command in RStudio or by using the Terminal of the conda environment created in the previous step:
install.packages("keras")
  1. Install keras with the tensorflow backend.
The keras library supports TensorFlow as the default backend. Theano and CNTK are other alternative backends that can be used instead of TensorFlow.

To install the CPU version, please refer to the following code:

install_keras(method = c("auto", "virtualenv", "conda"),  conda = "auto", version = "default", tensorflow = "default",  extra_packages = c("tensorflow-hub"))

For more details about this function, please go to https://keras.rstudio.com/reference/install_keras.html.

To install the GPU version, please refer to the following steps:

  1. Ensure that you have met all the installation prerequisites, including installing the CUDA and cuDNN libraries.
  2. Set the tensorflow argument's value to gpu in the install_keras() function:
install_keras(tensorflow = "gpu")

The preceding command will install the GPU version of keras in R.

How it works...

Keras and TensorFlow programs can be executed on both CPUs and GPUs, though these programs usually run faster on GPUs. If your system does not support an NVIDIA GPU, you only need to install the CPU version. However, if your system has an NVIDIA GPU that meets all the prerequisites and you need to run performance-critical applications, you should install the GPU version. To run the GPU version of TensorFlow, we need an NVIDIA GPU, and then we need to install a variety of software components (CUDA Toolkit v9.0, NVIDIA drivers, and cuDNN v7.0) on the system.

In steps 1 to 3, we created a new conda environment with both the R and Python kernels installed. In steps 4 and 5, we installed the keras library in the environment we created.

There's more...

The only supported installation method on Windows is conda. Therefore, you should install Anaconda 3.x for Windows before installing keras. The keras package uses the TensorFlow backend by default. If you want to switch to Theano or CNTK, call the use_backend() function after loading the keras library.

For the Theano backend, use the following command:

library(keras)
use_backend("theano")

For the CNTK backend, use the following command:

library(keras)
use_backend("cntk")

Now, your system is ready to train deep learning models.

See also

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime