![](/img/trans.png)
[英]How to use TensorFlow in R if I have Anaconda Python already installed?
[英]How to make keras in R use the tensorflow installed by Python
我已經使用以下命令執行了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
這是為CUDA 9.1提供的最新張力輪。 (比CUDA 8.0快3倍)
我可以在我的python代碼中成功調用它。
如何讓R中的keras調用上面python安裝的tensorflow? 我問的原因是因為我的默認安裝方法
keras::install_keras(method="conda", tensorflow = "gpu")
它無法識別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
這是因為R安裝方法需要調用tensorflow版本1.5.0,但仍未滿足CUDA 9.1的要求。
嘗試將它放在你的.bashrc
:
export KERAS_BACKEND='tensorflow'
或者根據此說明 ,您可以:
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")
然后keras將自動識別正確的張量流
R正在尋找CUDA 9.0版本,而不是最新的9.1版本。 您應該能夠對系統進行符號鏈接,使其最終位於9.1文件夾中; 就像是:
ln -s [path to cuda 9.0 it's looking for] [cuda 9.1]
或者,您可以卸載9.1並安裝9.0。 我相信你也需要cudnn版本7。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.