【问题标题】:How to make keras in R use the tensorflow installed by Python如何使R中的keras使用Python安装的tensorflow
【发布时间】:2018-07-11 08:06:27
【问题描述】:

我已经使用以下命令执行了张量流安装:

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 的最新 tensorflow 轮。 (比 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。

【问题讨论】:

  • 能否检查Rreticulate::py_module_available("tensorflow")的python通信是否成功?如果它返回FALSE,那么您可能需要在 R 中配置 python 和 tensorflow 路径。另外,请查看reticulate::py_config() 输出

标签: python r deep-learning keras


【解决方案1】:

试着把它放在你的.bashrc:

export KERAS_BACKEND='tensorflow'

或者基于这个instruction,你可以这样做:

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会自动识别正确的tensorflow

【讨论】:

    【解决方案2】:

    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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-04
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 2016-09-18
      • 2021-10-25
      相关资源
      最近更新 更多