当前位置: 移动技术网 > 网络运营>服务器>Linux > 解决Linux Tensorflow2.0安装问题

解决Linux Tensorflow2.0安装问题

2019年07月18日  | 移动技术网网络运营  | 我要评论
conda update conda
pip install tf-nightly-gpu-2.0-preview
conda install https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/cudnn-7.3.1-cuda10.0_0.tar.bz2
conda install https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/cudatoolkit-10.0.130-0.tar.bz2

说明:

  • 首先需要更新conda
  • 安装的是tf2.0最新版
  • cudnn7.3.1和cudatoolkit-10.0版本,可以下载下来本地安装
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/cudnn-7.3.1-cuda10.0_0.tar.bz2
conda install cudnn-7.3.1-cuda10.0_0.tar.bz2

出现的错误及解决方案

旧库问题

error: cannot uninstall 'wrapt'. it is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

旧版本依赖多,不能清晰的删除,此时应该忽略旧版本升级,即如下 解决办法: pip install tf-nightly-gpu-2.0-preview --ignore-installed wrapt

numpy版本问题

还有一个问题是说numpy存在旧版本,可以使用pip卸载numpy,直到提示没有可卸载的为止,然后重新安装numpy

驱动问题

tensorflow.python.framework.errors_impl.internalerror: cudagetdevice() failed. status: cuda driver version is insufficient for cuda runtime version

这是因为驱动版本不匹配导致的,可以到nvidia官网下载cuda10.0(和上面的一致)的驱动

安装命令: ,然后一路确定,最后使用 watch nvidia-smi

查看结果:


测试及其他

测试可用:

import tensorflow as tf
print(tf.__version__)
print(tf.keras.__version__)

if tf.test.is_gpu_available():
  device = "/gpu:0"
else:
  device = "/cpu:0"

print(device)

减少tensorflow输出信息

tensorflow的log信息共有四个等级,按重要性递增为:info(通知)<warning(警告)<error(错误)<fatal(致命的)

tf.compat.v1.logging.set_verbosity('error')

或者

import os
os.environ['tf_cpp_min_log_level'] = '3'

tensorflow2.0在pycharm下提示问题

tensorflow2.0 使用keras一般通过tensorflow.keras来使用,但是pycharm没有提示,原因是因为实际的keras路径放在tensorflow/python/keras,但是在程序中tensorflow有没有python这个目录,解决方法如下:

try:
  import tensorflow.python.keras as keras
except:
  import tensorflow.keras as keras

这样pycharm既可以有提示,同时也不需要在程序运行的时候修改代码了。

总结

以上所述是小编给大家介绍的解决linux tensorflow2.0安装问题,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网