Introduction

With the new versions of the keras and tensorflow packages, the installation process is considerably simpler.

While one can use any python3 installation, we recommend using conda as it works well with the R packages. So choose one of the two below that applies to your situation.

1. Existing conda installation.

If one has an existing conda installation, and an already-created environment named r-tensorflow, then the following should work.

install.packages("keras")
keras::install_keras(method = "conda", python_version = "3.10")

The first installs the R keras package along with its dependencies and the second installs the python keras package for conda. Note the specification of the python version—this is necessary because tensorflow packages for newer python versions may not be available.

2. No existing conda installation

In this case, one needs to install conda also.

install.packages("keras")
reticulate::install_miniconda()
keras::install_keras(method = "conda", python_version = "3.10")

The only difference from the above in this case is that we use reticulate, a dependency of keras, to install conda into an environment named r-tensorflow by default. The note about the python version applies here too.

Small change in keras lab code

The latest version of the Ch10-deeplearning-lab-keras lab includes an additional line to accommodate this new version of the keras package, just after the library(keras) command:

library(keras)
reticulate::use_condaenv(condaenv = "r-tensorflow")

This is required for the section using pretrained models.