Linux Tensorflow2.0安装
安装Tensorflow2.0
conda update condapip install tf-nightly-gpu-2.0-previewconda install https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/cudnn-7.3.1-cuda10.0_0.tar.bz2conda 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.bz2conda 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(和上面的一致)的驱动
安装命令:bash ./NVIDIA-Linux-x86_64-410.104.run,然后一路确定,最后使用watch nvidia-smi查看结果:
测试及其他
测试可用:
import tensorflow as tfprint(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(通知)
tf.compat.v1.logging.set_verbosity('ERROR')复制代码
或者
import osos.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 kerasexcept: import tensorflow.keras as keras复制代码
这样pycharm既可以有提示,同时也不需要在程序运行的时候修改代码了。
Tensorflow2.0使用中的BUG
- Tensorflow 2.0会覆盖日志记录配置
- Tensorflow 2.0使用在dataset.map()中输入tf.string类型的tf.py_function会生成dtype警告