Does "install_keras()" also install tensorflow?

I'm trying to set up an RStudio environment to study deep learning, running R/RStudio 4.3.1 on a university cluster desktop under ubuntu 22.04, using CUDA-11.6 and a GPU. The desktop is set up by the cluster, so I don't have access to how the desktop actually manages the GPU. acsess. I have asked the admins to help me with this. But my experience has raised a couple of questions about my workspace setup.
I use the following set up within RStudio:

library(reticulate)
virtualenv_create("r-reticulate", python = install_python())
library(keras)
install_keras(envname = "r-reticulate")
(R studio restarts here)
library(tensorflow)
install_tensorflow(envname = "r-tensorflow", version = '2.15')

According to Deep Learning with R, 2nd edition, installing keras, among other things, also loads tensorflow. But when I run install_keras() alone, my code can't find an installed tensorflow. The error language suggests running the above command to "install_tensorflow(envname = "r-tensorflow"). Now everything seems to work correctly other than that any tensorflow command can't find the GPU, so that I can only use CPU hardware.

My two questions:
a. Does the current version of keras::install_keras() actually still also install tensorflow, as stated in the Deep Learning book? If so, why does R not then find the tensorflow?
b. "Install_tensorflow(envname = 'r-reticulate')" doesn't work. I need to use "(install_tensorflow(envname = 'r-tensorflow)". Does the use of two different environments for reticulate/keras and for tensorflow cause problems?

My understanding is that the environments work basically to install specific versions of various packages for a given application, and that this is achieved by modifying the path variable to point to the specific instances of packages within the specified environments. I would have thought that installing tensorflow within the r-reticulate environment would avoid problems with the path, but if I install tensorflow to the r-reticulate environment, R can't find the tensor flow.

I'm obviously something of a newbie to deep learning (but with years of experience with R and RStudio). I would deeply appreciate any help understanding better how the environments work to point to specific package versions. Many thanks in advance. Larry

Hi, yes, keras::install_keras() does also install tensorflow.

If, after calling install_keras() or install_tensorflow(), you are unable to load tensorflow or keras, then that means that either
a) installation failed or was unsuccessful. Reading the output from install_keras() usually indicates what went wrong, though in some rare cases, the failure is silent and doesn't appear until you actually call import("tensorflow"). If you're running into this, you can file an issue on github for help. Another good first step is to try with a different python installation or version.
b) reticulate is, for some reason, using a different python installation from the one that tensorflow was installed into. Some common reasons might be

  • The RStudio IDE has a setting pointing it at a different Python (under Options > Python)
  • There is a .Renviron or .Rprofile defining RETICULATE_PYTHON or calling use_python()
  • There is another package using reticulate activating a different python installation (e.g., radian, pysparklyr)

This is often best diagnosed by looking at reticulate::py_config() and observing which python is being use and why, and comparing with python that is being called in the output from install_keras()

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.