从零开始配置tensorflow深度学习环境(含cuda以及其他依赖)

前言

近日因为某些原因将自己电脑重置了,特来记录一下从零开始配置tensorflow深度学习环境的过程

开发语言

本文采用python语言3.8.2版本作为解释器进行开发
从官网下载并按照指示进行安装,并将python加入的环境变量中

编辑器

采用jetbrains的PyCharm 2020.2.1 x64作为编辑器进行编辑
从官网下载后进行安装配置
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

cuda以及cudnn的安装

查看是否具有独立显卡以及支不支持cuda的安装

首先我们要确定本机是否有独立显卡,在计算机管理−设备管理器-显示适配器中,查看是否有独立显卡。
在这里插入图片描述

在这里插入图片描述

到这个网站查找是否可以安装
https://developer.nvidia.com/cuda-gpus
因为我的显卡是GeForce RTX的,所以点下面这个,查看支持的版本
在这里插入图片描述

可以看到3060的是支持的

查看支持的cuda版本

打开NVIDIA控制面板,选择:帮助->系统信息查看到我这里需要的是cuda 11.8
在这里插入图片描述

下载安装cuda

Cuda的下载地址:https://developer.nvidia.com/cuda-downloads
在这里插入图片描述

根据之前看到的信息选择64位windows版本的version 为11的cuda进行下载
在这里插入图片描述

下载好之后开始安装

在这里插入图片描述
在这里插入图片描述

选择自定义
在这里插入图片描述

这里因为太占用C盘空间,所谓我们在D盘按照安装位置新建两个文件夹

在这里插入图片描述
在这里插入图片描述

更改后的位置
在这里插入图片描述

安装完成
打开环境变量可以看到cuda位置已经被配置到了环境变量里了
在这里插入图片描述

重启电脑后输入nvcc -V后显示类似信息说明安装成功
在这里插入图片描述

cudnn的下载和配置

Cudnn对照:https://blog.youkuaiyun.com/DuLNode/article/details/123428294
根据对照表下载相应版本的cudnn
在官网注册之后下载相应版本的cudnn
官网地址:https://developer.nvidia.com/cudnn-download-survey
将下载好的cudnn解压后

将三个文件夹复制到cuda对应的文件夹,我的路径是:D:\NVIDIA GPU Computing Toolkit(就是之前新改的地址)
将三个文件夹的路径配置到环境变量

在这里插入图片描述
在这里插入图片描述

cuda与cudnn的检验

找到cuda安装的路径下的demo_suite文件夹,我这里的路径是D:\NVIDIA GPU Computing Toolkit\extras\demo_suite
打开cmd窗口切换到demo_suite文件夹
依次运行deviceQuery.exe和bandwidthTest.exe
运行结果如下,说明安装成功

在这里插入图片描述
在这里插入图片描述

安装tensorflow依赖

安装适用于 Visual Studio 2015、2017 和 2019 的 Microsoft Visual C++ 可再发行软件包。从 TensorFlow 2.1.0 版开始,此软件包需要 msvcp140_1.dll 文件(旧版可再发行软件包可能不提供此文件)。该可再发行软件包随附在 Visual Studio 2019 中,但可以单独安装:
https://learn.microsoft.com/zh-CN/cpp/windows/latest-supported-vc-redist?view=msvc-170
在这里插入图片描述

在页面中向下滚动到“Visual Studio 2015、2017 和 2019”部分。

依赖包的安装

更新pip

python -m pip install --upgrade pip

换源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

安装tensorflow以及其他常用包

pip install pillow
pip install tensorflow
pip install tensorflow-gpu # 高版本的tensorflow以不再区分cpu版本和gpu版本,这个可以不安装
pip install opencv-contrib-python
pip install matplotlib
pip install scipy

如果需要进行UI开发还可以安装PyQt5

使用pip安装包

pip install PyQt5
pip install PyQt5-tools

找到python的site-pakages(我的site-pakages在D:\Python\Python38\Lib\site-packages路径)路径下的pyqt5-tools
在这里插入图片描述
将pyqt5-tools路径加入环境变量
在这里插入图片描述

自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.支持mkl,无MPI; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 配置信息: 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 编译: hp@dla:~/work/ts_compile/tensorflow$ bazel build --config=opt --config=mkl --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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

艾醒(AiXing-w)

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

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

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

打赏作者

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

抵扣说明:

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

余额充值