Issue
I am using R4.0.1 and Rstudio1.3.959 on windows 10. I have installed tensor flow:
install.packages("tensorflow")
library(tensorflow)
install_tensorflow(method = "conda", conda_python_version = 3.6)
I checked the installation success by:
library(tensorflow)
tf$constant("Hellow Tensorflow")
Output: Tensor("Const:0", shape=(), dtype=string)
tf$constant(1.5)
Output: Tensor("Const_1:0", shape=(), dtype=float32)
I further checked by:
tf_config()
Output: TensorFlow v1.13.2 () Python v3.6 (C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate/python.exe)
From here it seems the tensor flow is installed properly and is working fine. However, I faced problems in loading Keras library. I did the following:
install.packages("keras")
library(keras)
As I load the library, it gives the following error
Error: package or namespace load failed for ‘keras’:
.onLoad failed in loadNamespace() for 'keras', details:
call: py_module_import(module, convert = convert)
error: ImportError: cannot import name 'swish'
Detailed traceback:
File "C:\Users\user\AppData\Local\r-miniconda\envs\r-reticulate\lib\site-packages\tensorflow\keras\__init__.py", line 14, in <module>
from . import activations
File "C:\Users\user\AppData\Local\r-miniconda\envs\r-reticulate\lib\site-packages\tensorflow\keras\activations\__init__.py", line 23, in <module>
from tensorflow.python.keras.activations import swish
Since the keras package could not be loaded I cannot run the following code
install_keras(method = "conda")
I could get additional information as below:
library(reticulate)
> py_discover_config("keras")
python: C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
libpython: C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate/python36.dll
pythonhome: C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate
version: 3.6.10 |Anaconda, Inc.| (default, May 7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
numpy_version: 1.18.1
I could also see that default python version in use as:
Sys.which("python")
python
"C:\\Users\\user\\AppData\\Local\\R-MINI~1\\envs\\R-RETI~1\\python.exe"
I would be grateful if anyone can solve this installation issue. Thanks
Solution
This might be a bit different but I find it easier to hand manage dependent env. So you can open conda prompt and execute:
conda create -n env_name python=3.6 tensorflow
Then in R before you do anything call
library(keras)
library(tensorflow)
use_condaenv(condaenv = "env_name",required = T)
By default you wil get TF 2.xx, you can specify that in conda env.
EDIT: For TF gpu you need to specify conda create -n env_name python=3.6 tensorflow-gpu
and you will get CUDa and CUDNN if you have GPU on your PC.
Answered By - JacobJacox
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.