Getting things ready for Keras

To use Keras properly, many other packages and programs must be installed. The way any of these programs are installed might vary according to the Operational System (OS) you are using, and I shall point to the websites where you can find download links and instructions.

Some cloud servers can be easily prepared for the use of R and Keras, while others will require more work to be done. Selecting the appropriate server and developing a routine to make these environments ready, as well as computing the time you will need to get it done, is very important.

Both the Keras library and TensorFlow are written in Python, so it makes sense to get it installed first. Get version 3.x through the official website: https://python.org.

You can install it through Anaconda if you prefer (https://www.anaconda.com/download). Now, let's install the following Python modules (or libraries if you will):

  • numpy
  • scipy
  • gaphviz 
  • keras
  • tensorflow
  • matplotlib
  • pydot-ng
  • h5py
You can find the gaphviz library https://graphviz.gitlab.io/download/.

We can install Python modules using the reticulate package but only if you installed Anaconda and marked the PATH option. If you want to install them using reticulate, install the package first:

if(!require('reticulate')){install.packages('reticulate')}
library(reticulate)

The next step is to use py_install to install all the packages, and this step can take several minutes:

py_install('numpy')
py_install('scipy')
py_install('graphviz')
py_install('keras')
py_install('tensorflow')
py_install('matplotlib')
py_install('pydot-ng')
py_install('h5py')

If the pip command is available in your system, there is a way to install them through the R console:

modules <- c('numpy','scipy','graphviz',
'keras', 'tensorflow',
'matplotlib','pydot-ng','h5py')
for(i in modules){
system(paste('python -m pip install --upgrade', i, sep = ' '))
}

It is also recommended to install a Basic Linear Algebra Subprogram (BLAS) to optimize some operations that may take place on your machine. OpenBLAS might optimize tensor operations running on your CPU. The following website has download links, installation instructions, and a manual: https://www.openblas.net/.

Training your networks using GPU is usually faster than training them in a CPU. If you have an NVIDIA graphic card, it might be possible for Keras to train your networks with it. Make sure your card is compatible with CUDA. If it is, follow the next steps:

    1. Update your driver (http://www.nvidia.com/Download/index.aspx?)
    2. Download and install CUDA (https://developer.nvidia.com/cuda-zone)
    3. Download and install cuDNN (https://developer.nvidia.com/cudnn)

It's time to turn back to R's console again. It's better to have a recent version of the reticulate package installed; make sure to have devtools installed, and run the following:

devtools::install_github('rstudio/reticulate')

Package reticulate is meant to run Python through R. Having this version from RStudio's GitHub might prevent some annoying bugs coming up while running Keras with R. If you're missing devtools, run install_packages('devtools') before running the latter code.
Another thing to do in your R console is to install the keras package and Keras itself:

install.packages('keras')
library(keras)
install_keras()

Notice that the keras package was not only installed but it was installed, loaded, and had a function called (install_keras()). Having the environment properly set is really important. Although this section covers lots of requirements, the real extent of need may vary from context to context. Keep an eye open for any warning sign that may arise.

The preparations have been made, so it's finally time to get practical with Keras. The next topic will discuss data gathering, preprocessing, network design, training, and evaluation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.174