[英]How to make keras in R use the tensorflow installed by Python
I have already performed the tensor flow installation with the following command: 我已经使用以下命令执行了tensor flow安装:
pip install --ignore-installed https://github.com/mind/wheels/releases/download/tf1.5-gpu-cuda91-nomkl/tensorflow-1.5.0-cp27-cp27mu-linux_x86_64.whl
This is the latest tensorflow wheel catered for CUDA 9.1. 这是为CUDA 9.1提供的最新张力轮。 (3x faster than CUDA 8.0)
(比CUDA 8.0快3倍)
And I can call it successfully in my python code. 我可以在我的python代码中成功调用它。
How can I make the keras in R to call the tensorflow installed by python above? 如何让R中的keras调用上面python安装的tensorflow? The reason I asked that because I the default installation method
我问的原因是因为我的默认安装方法
keras::install_keras(method="conda", tensorflow = "gpu")
It failed to recognize the cuda-9.1 library. 它无法识别cuda-9.1库。
> conv_base <- keras::application_vgg16(
+ weights = "imagenet",
+ include_top = FALSE,
+ input_shape = c(150, 150, 3)
+ )
/home/ubuntu/anaconda2/envs/r-tensorflow/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Error: ImportError: Traceback (most recent call last):
File "/home/ubuntu/anaconda2/envs/r-tensorflow/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/ubuntu/anaconda2/envs/r-tensorflow/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/ubuntu/anaconda2/envs/r-tensorflow/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
This is because R installation method calling for tensorflow version 1.5.0 that is still not catered for CUDA 9.1. 这是因为R安装方法需要调用tensorflow版本1.5.0,但仍未满足CUDA 9.1的要求。
Try to put this in your .bashrc
: 尝试将它放在你的
.bashrc
:
export KERAS_BACKEND='tensorflow'
Or based on this instruction , you can do: 或者根据此说明 ,您可以:
tensorflow::install_tensorflow(version = "https://github.com/mind/wheels/releases/download/tf1.5-gpu-cuda91-nomkl/tensorflow-1.5.0-cp27-cp27mu-linux_x86_64.whl")
Then keras will automatically identify the correct tensorflow 然后keras将自动识别正确的张量流
R is looking for the CUDA 9.0 version, rather than the latest 9.1. R正在寻找CUDA 9.0版本,而不是最新的9.1版本。 You should be able to symlink your system so it ends up at the 9.1 folder instead;
您应该能够对系统进行符号链接,使其最终位于9.1文件夹中; something like:
就像是:
ln -s [path to cuda 9.0 it's looking for] [cuda 9.1]
Alternatively you may be able to uninstall 9.1 and install 9.0. 或者,您可以卸载9.1并安装9.0。 I believe you will also need cudnn version 7.
我相信你也需要cudnn版本7。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.