Guaranteeing the absence of compatibility issues between tensorflow, tensorflow-probability, greta, reticulate, python, numpy, etc. is quite the challenge. I have two methods that seem robust: 1) for using the CRAN version of greta (recommended for new users) and 2) for using the dev version of greta.
Using CRAN version of greta (currently 0.3.0)
- Install miniconda (https://docs.conda.io/en/latest/miniconda.html)
- At anaconda command prompt run the following commands (NOTE: The first command is long; it starts with
conda create...
and ends withnumpy=1.15
):conda create -n r-tensorflow python=3.6 tensorflow=1.11 pyyaml requests Pillow pip numpy=1.15
conda activate r-tensorflow
pip install tensorflow-probability==0.4
- Open a brand-new R session and use the following commands:
install.packages("greta")
library(greta)
Using dev version of greta
- At anaconda command prompt run the following commands (NOTE: The first command is long; it starts with
conda create...
and ends withPillow
)::conda create -n r-tensorflow python=3.6 tensorflow=1.13.1 pip pyyaml requests Pillow
conda activate r-tensorflow
pip install tensorflow-probability==0.6.0
- Open a brand-new R session and use the following commands:
devtools::install_github("greta-dev/greta")
library(greta)
Random lessons I’ve learned that might help someone:
- Do not use conda-forge for installation. Its version of tensorflow is not optimized with Intel’s libraries and runs slower. Helpful command:
conda config --remove channels conda-forge
. And refollow above instructions afterconda remove -n r-tensorflow --all
-
Tensor conversion requested dtype int64 ...
error is usually due to using dev branch of greta with Tensorflow <= 1.11. -
reticulate::py_numpy_available()
returnsFALSE
when trying to use python 3.7. Use python 3.6 for stability. - Using
tensorflow-probability=0.5
andtensorflow>=1.12
leads to alot of warning messages about deprecated functions when running greta. - The following lines might help R use the right version of tensorflow if tensorflow or tensorflow-probability is not found:
# start new R session and run the below (otherwise R will use wrong info)
# make sure the path below is changed (i.e. "<USERNAME>")
reticulate::use_condaenv("r-tensorflow")
reticulate::use_python("c:/Users/<USERNAME>/Miniconda3/envs/r-tensorflow/", required = TRUE)
reticulate::py_numpy_available(initialize = TRUE)
# Use the below to check that conda and python are sourced from the right places
reticulate::py_config()
- Do not have R/RStudio open when changing the Python environment via conda. This can lead to permission errors.