A (hopefully) Useful Guide to Installing GPU Version of Keras in R

Installing GPU Version of Keras in R

Follow these 6 semi-easy steps in order to get the begin achieving your deeplearning goals. These were all tested on Windows 10 using RStudio, but should be the same for other operating systems.

  1. Download the Anaconda installer compatible with your operating system that supports Python 3. Install said installer pressing next and agreeing. On the advanced options window tick the first box so Anaconda adds the installation directory to you system PATH. This will allow the Keras in R package to find it, if you don’t tick it you can add it to your system PATH manually later but this is not something trivial for everybody. You can also make Anaconda your default Python, but it shouldn't be necessary.
  2. Download and install Cuda Toolkit 9.0 (Sept. 2017). Agree to the classic never-read agreements and choose the express installation. This step quite slow, or was for me at least, but straightforward.
  3. Download the NVIDIA CUDA Deep Neural Network library (cuDNN). This allows you to use the graphics card for more than graphics processing. This step is (unnecessarily) long because it requires a membership of the NVIDIA Developer Program, which is is really just creating an account. Create and account by clicking on the green join button and download cuDNN after login in. Download the latest version compatible with CUDA 9.0 and your operating system which, at the time of writing this, is cuDNN v7.0.5.
  4. Extract the files from the zip file, you should have 3 folders: bin, include and lib. Go to the NVIDIA GPU Computing Toolkit directory (by default this is something similar to :\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0 ) where you have, among others, three folders with the same names as the ones extractad from the cuDNN. Move the files located in the bin folder of cuDNN to the bin folder in the NVIDIA GPU computing toolkit,choose replace when prompted. Do the same for the include and lib folders.
  5. Open RStudio (finally) and run the following code. This code first installs and load the devtools package which allows you to install Keras from github. Keras can also be installed for CRAN but you’re not getting the latest version and this may cause problems with Python. Next you need to install the reticulate package which serves as an interface for the Python modules. Next you install the Keras package from github (aided by the previously installed devtools package). After installing Keras form github you should be able to easily install the GPU enabled version of Keras.
install.packages(“devtools”)
library(devtools)
install.packages(“reticulate”)
library(reticulate)
install_github(“rstudio/keras”)
library(keras)
install_keras(tensorflow = “gpu”)
reticulate::py_config()
reticulate::py_module_available(“keras”)

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store