How to install Keras and Tensorflow in Rstudio?
Keras and Tensorflow are Python libraries to train deep learning models. where as R has used to train deep learning models by the library available in Rstudio keras and tensorflow. Keras uses the conda environment to access the keras library in python which uses Tensorflow as a BackEnd. To provide the conda environment Anaconda3 5.1.0 is CLI is used. Before installing keras and tensorflow in Rstudio, Install Anaconda3 and set the conda and python environments to access the keras library.
ANACONDA3 5.1.0
Anaconda is a
INSTALLING
ANACONDA FOR RSTUDIO IN WINDOWS
1. Visit the Anaconda page https://www.anaconda.com/download/#windows
and download windows installer for Python 3.6 version according to your OS
type 64 bit/32 bit.
2. Install Anaconda by double click on the downloaded exe file, and follow the installation wizard.
3. After finishing the installation, verify whether the Conda is
installed correctly or not
4. Open the Anaconda3 terminal, and give the following command
to check.
Conda –V
It
will show the installation version of Conda environment like,
conda 4.3.34
conda 4.3.34
5. Verify whether the Python is installed correctly or not by
giving this command.
python –V
It will show the Installation version of Python environment
like,
6. If the setup has any errors in conda or python. Check whether your conda package has updated
or not. To update your conda package, use the following command.
conda update –n base conda
conda update anaconda
KERAS
ü Keras
provides a high-level neural networks API developed with a focus on enabling
fast experimentation. Keras has the following key features:
ü Allows
the same code to run on CPU or on GPU,.
ü User-friendly
API which makes it easy to quickly prototype deep learning models.
ü Supports
arbitrary network architectures: multi-input or multi-output models, layer
sharing, model sharing, etc.
ü Is
capable of running on top of multiple back-ends including Tensorflow, CNTK
or Theano.
TENSORFLOW
ü TensorFlow is
an open source software library for numerical computation using data flow
graphs. Nodes in the graph represent mathematical operations, while the graph
edges represent the multidimensional data arrays (tensors) communicated between
them.
ü The
flexible architecture allows you to deploy computation to one or more CPUs or
GPUs in a desktop, server, or mobile device with a single API.
ü The TensorFlow
API is composed of a set of Python modules that enable constructing and
executing TensorFlow graphs. The tensorflow package provides access to the
complete TensorFlow API from within R.
INSTALLATION
OF KERAS WITH TENSORFLOW AT THE BACKEND.
The steps to install Keras in RStudio is
very simple. If we follow the below steps, first Neural Network Model in R would be ready.
Install.packages(“devtools”)
devtools::install_github(“rstudio/keras”)
The above step will load the keras library
from the GitHub repository. Now it is time to load keras into R and
install tensorflow.
library(keras)
By default, RStudio loads the CPU version of tensorflow.
Use the below command to download the CPU version of tensorflow.
install_tensorflow()
To install the tensorflow version with GPU
support for a single user/desktop system, use the below command.
Install_tensorflow(gpu=TRUE)