Tensorflow2.0 GPU版本安装(CUDA10.0 + cuDNN7.5 + Tensorflow2.0 Alpha)

(本人小白一名,总结了一些自己的操作经验,仅供参考)


前段时间Tensorflow 2.0 Alpha版本发布,作为刚入门深度学习的小白之前没有学过 Tensorflow1.x 系列,只学过一些keras,也懒得再学习 Tensorflow1.x 系列了,直接平滑过渡到 Tensorflow 2.0 多好。首先面临的问题就是CUDA等的安装及配置。

操作过程中参考了一些网络上的教程,但版本都不太匹配,并且操作似乎也不太一致,把自己整得很懵。但胡乱尝试一通,总算是成功了。效果如下:

$ nvidia-smi
Sun May 12 13:19:09 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.104      Driver Version: 410.104      CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940M        On   | 00000000:01:00.0 Off |                  N/A |
| N/A   45C    P5    N/A /  N/A |    246MiB /  2004MiB |     11%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1339      G   /usr/lib/xorg/Xorg                           126MiB |
|    0      1497      G   /usr/bin/gnome-shell                         116MiB |
|    0      2432      G   /usr/lib/firefox/firefox                       1MiB |
+-----------------------------------------------------------------------------+

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

$ ls
bin  cuda  cuda-10.0  etc  games  include  lib  man  sbin  share  src

在一个技术群里问了一下,一个大佬说这样就算安装成功了,经过尝试发现之后的进一步操作也没有出现问题。
下面就来简单捋一下我的操作经历。


首先我们参考的当然是Tensorflow的官方说明:https://www.tensorflow.org/install/gpu

硬件要求

系统支持以下支持 GPU 的设备:

CUDA® 计算能力为 3.5 或更高的 NVIDIA® GPU 卡。请参阅支持 CUDA 的 GPU 卡列表。

软件要求

必须在系统中安装以下 NVIDIA® 软件:
NVIDIA® GPU 驱动程序 - CUDA 10.0 需要 410.x 或更高版本。
CUDA® 工具包 - TensorFlow 支持 CUDA 10.0(TensorFlow 1.13.0 及更高版本)
CUDA 工具包附带的 CUPTI。
cuDNN SDK(7.4.1 及更高版本)
(可选)TensorRT 5.0,可缩短在某些模型上进行推断的延迟并提高吞吐量。

这里详细列出了安装Tensorflow 2.0 Alpha GPU版本的前提要求。下面就开始操作:

1. 安装CUDA

这一步在Tensorflow的官方教程中有详细介绍,直接按照上面的教程操作即可:

Ubuntu 18.04 (CUDA 10)

   #Add NVIDIA package repositories
   wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
   sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
   sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
   sudo apt-get update
   wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
   sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
   sudo apt-get update

   # Install NVIDIA driver
   sudo apt-get install --no-install-recommends nvidia-driver-410
   # Reboot. Check that GPUs are visible using the command: nvidia-smi

   # Install development and runtime libraries (~4GB)
   sudo apt-get install --no-install-recommends \
       cuda-10-0 \
       libcudnn7=7.4.1.5-1+cuda10.0  \
       libcudnn7-dev=7.4.1.5-1+cuda10.0
   

   # Install TensorRT. Requires that libcudnn7 is installed above.
   sudo apt-get update && \
           sudo apt-get install nvinfer-runtime-trt-repo-ubuntu1804-5.0.2-ga-cuda10.0 \
           && sudo apt-get update \
           && sudo apt-get install -y --no-install-recommends libnvinfer-dev=5.0.2-1+cuda10.0

2. 安装cuDNN

这里我们安装cuDNN 7.5
首先打开连接 https://developer.nvidia.com/rdp/cudnn-archive 下载对应的版本。
在这里插入图片描述点击第三个,下载压缩包 cudnn-10.0-linux-x64-v7.5.0.56.tgz
下在之后解压,拷贝,配置环境变量

# 解压
$ tar -zxvf cudnn-10.0-linux-x64-v7.5.0.56.tgz

# 拷贝
$ cd cudnn-10.0-linux-x64-v7.5.0.56
$ sudo cp cuda/include/cudnn.h /usr/local/cuda-10.0/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64

# 修改权限
$ sudo chmod a+r /usr/local/cuda-10.0/include/cudnn.h /usr/local/cuda-10.0/lib64/libcudnn*

将以下内容追加到 ~/.bashrc 文件末尾:

export PATH=/usr/local/cuda-10.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
export CUDNN_PATH="/usr/local/cuda-10.0/lib64/libcudnn.so"

3. 验证cuDNN

$ echo -e '#include"cudnn.h"\n void main(){}' | nvcc -x c - -o /dev/null -lcudnn

上面这个命令不报错就说明没问题。

4. 安装Tensorflow2.0 GPU版本

可以先创建一个名为 tensorflow2_gpu 的虚拟环境,创建好之后进入虚拟环境,用pip安装Tensorflow2.0 GPU版本:

pip install tensorflow-gpu==2.0.0-alpha0

安装成功的话就大功告成啦!赶紧去使用试试吧

其他说明

安装过程中难免会出现一些其他问题,报错或者其他提示。出现这种情况就把报错复制到百度里,基本都会找到相关的解决办法。遇到其他问题也可以请教身边的大佬。
总之要不怕麻烦动起手来!

祝你操作顺利!

参考

[1]http://www.cnblogs.com/journeyonmyway/p/10316292.html
[2]https://www.tensorflow.org/install/gpu
[3]https://blog.csdn.net/weixin_42106049/article/details/85065489

  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]://home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: bazel build --config=opt --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
### 回答1: OpenCV是一个开源的计算机视觉和机器学习库,可以方便地处理图像和视频。而CUDA(Compute Unified Device Architecture)是由NVIDIA开发的一种并行计算架构,可以加速图形处理器(GPU)上的计算任务。 OpenCV 4.5.1是OpenCV的一个版本,它提供了丰富的功能和算法,用于图像和视频处理、特征提取、目标检测等任务。这个版本可以在Windows 10操作系统上使用,并且可以与Visual Studio 2017集成,提供开发环境和调试工具。 CUDA 10.0是NVIDIA的一个版本,它支持NVIDIA GPU上的并行计算任务。它允许开发人员使用C语言、C++或CUDA自己的扩展语言编写并行计算代码,以加速计算密集型任务。例如,在图像处理中,可以使用CUDA加速OpenCV算法,从而提高计算性能。 而cuDNNCUDA Deep Neural Network library)是NVIDIA专门为深度学习任务开发的一个库。它提供了一组高性能的深度神经网络的基本操作和优化算法,可以与CUDA和OpenCV结合使用。 综上所述,OpenCV 4.5.1可以与CUDA 10.0cuDNN 7.6.0集成使用。开发者可以在Visual Studio 2017中使用这些工具和库进行图像处理和机器学习任务的开发和优化。通过使用CUDA加速,可以提高计算性能,而cuDNN可以提供深度学习任务所需的算法和操作。 ### 回答2: OpenCV 4.5.1是一个计算机视觉库,用于在计算机视觉和机器学习项目中进行图像和视频处理。VS2017是一个集成开发环境(IDE),用于Windows操作系统上的软件开发。CUDA(Compute Unified Device Architecture)是一个用于GPU计算的并行计算平台和API模型。CUDNN是NVIDIA深度神经网络库,用于在GPU上加速深度学习任务。 在Windows 10上使用VS2017来编译OpenCV 4.5.1,并在CUDA 10.0CUDNN 7.6.0的支持下进行构建可以提供更好的计算性能和加速。CUDA 10.0提供了与CUDA架构和驱动程序的兼容性,并支持许多NVIDIA GPUCUDNN 7.6.0是基于CUDA的深度神经网络库,可以加速深度学习任务的训练和推理。 使用VS2017编译OpenCV可以让开发者方便地在Windows平台上进行开发和调试。VS2017提供了强大的集成开发环境,它可以帮助开发者编写、调试和测试程序。通过配置CUDA 10.0CUDNN 7.6.0来支持OpenCV的GPU加速,可以进一步提高图像和视频处理的速度和效率。 总结来说,使用OpenCV 4.5.1、VS2017、Windows 10、CUDA 10.0CUDNN 7.6.0可以实现在Windows平台上的高效计算机视觉和机器学习开发。这种配置可以提供更好的性能和加速,特别是在需要处理大量图像和视频、进行深度学习任务的情况下。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

本初-ben

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值