window10 深度学习环境搭建(cuda+cdDNN+pytorch)

1.CUDA下载安装

1.进入系统的英伟达文件夹查看显卡信息

cd C:\Program Files\NVIDIA Corporation

输入nvidia-smi查看显卡信息,可以看到本电脑支持的cuda版本是11.0

在这里插入图片描述

查看支持cuda的显卡和显卡的计算能力
https://developer.nvidia.com/zh-cn/cuda-gpus

2.下载cuda

全部版本的cuda下载 https://developer.nvidia.com/cuda-toolkit-archive

cuda11下载链接 https://developer.nvidia.com/zh-cn/cuda-downloads

(本处我选择的cuda版本是11.1,虽然和上面查出来的版本不一样,但安装包第一步进行系统检查的时候也通过了)

在这里插入图片描述

安装程序类型选择的是local(local版本3.1G,用迅雷下载也很快,一开始使用network版本下载虽然很快,但是安装联网不知道为什么特别慢)

3.安装

在这里插入图片描述

自定义安装中,只勾选CUDA

在这里插入图片描述

记住这个安装位置,后面还有用

在这里插入图片描述

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

安装完成后测试,输入

nvcc -V

在这里插入图片描述

2.cuDNN下载配置

1.cuDNN下载

https://developer.nvidia.com/rdp/cudnn-archive

选择对应的CUDA版本

在这里插入图片描述

cuDNN下载需要登陆,没有账号的可以注册一个,很快

在这里插入图片描述

需要登陆或注册,登陆后提示即可继续下载(火狐下载很慢,用迅雷)

在这里插入图片描述

2.配置

解压下载的cuDNN压缩包,得到如下

在这里插入图片描述

此时,需要用到上述CUDA安装的地址,我的地址如下

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1

把解压后的bin,include,lib三个文件夹直接选中,然后复制到CUDA的安装地址中(直接选中复制即可,没有重复冲突之类的东西)

3.检查系统变量配置

通常情况,安装后会自动帮我们配置环境变量,以防万一,我们进行一下检查,打开此电脑-属性-高级系统设置-环境变量

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

Path中:

在这里插入图片描述

3.下载安装anoconda

在anaconda的官网,我选择的individual版本,选择对应的操作系统下载安装即可

https://www.anaconda.com/products/individual

在这里插入图片描述

我下载时,只有Python3.8的版本,但此时我电脑上已经安装了Python3.9,要注意安装conda后电脑上存在两个版本的Python。conda的Python安装路径在anaconda下的pkgs文件夹下

安装时,没有选择Add Anaconda to my PATH environment variable选项,需要使用时打开anaconda powershell prompt即可。

安装后,我们改一下anaconda默认下载源,在anaconda的控制台中输入,可以在c盘-用户-个人用户下看到.condac文件

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

4.pytorch安装

进入官网选择对应的版本

https://pytorch.org/get-started/locally/

在这里插入图片描述

进入到anaconda的命令台,粘贴下面的命令行,即开始安装(试了一下吧版本改成11.1,不成功)

在这里插入图片描述

提示的选择y进行下载安装即可

PS:安装期间报错InvalidArchiveError(‘Error with archive D:\Program Files\Anaconda\pkgs\numpy-base-1.19.1-py36ha3

解决方法https://blog.csdn.net/u011208984/article/details/109176212

在anaconda的控制台进行torch安装成功的测试
在这里插入图片描述

python
Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> a=torch.cuda.is_available();
>>> print(a)
True
>>> ngpu= 1
>>> device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
>>> print(device)
cuda:0
>>> print(torch.cuda.get_device_name(0))
GeForce RTX 2060
>>> print(torch.rand(3,3).cuda())
tensor([[0.9715, 0.1951, 0.4351],
        [0.4067, 0.3654, 0.8233],
        [0.4502, 0.8057, 0.5741]], device='cuda:0')

5.tensorflow-gpu的安装(安装了cuda11,没有对应的版本号,未成功)

在anaconda的控制台下输入,会在anaconda的envs文件夹中创建名为tensorflow的文件夹

conda create –name tensorflow python=3.8

1.在cmd进入conda下的script目录

C:\Users\lenovo>D:
D:\>cd D:\code\anaconda3\Scripts

2.创建虚环境,procced选项选即可

conda create –n py38 python=3.8

命令执行后提示

在这里插入图片描述

激活环境
conda activate py38
退出环境
conda deactivate

3.查看tensorflow和对应cuda的版本

在这里插入图片描述

https://tensorflow.google.cn/install/source_windows

在tensorflow的官网查看Python和pip版本要求

https://tensorflow.google.cn/install/pip

4.安装tensorflow-gpu

在anaconda的控制台下激活刚才创建的虚环境,并查看 Python对应的版本和pip对应的版本

(base) PS C:\Users\lenovo> conda activate py38
(py38) PS C:\Users\lenovo> python --version
Python 3.8.5
(py38) PS C:\Users\lenovo> pip --version
pip 20.3 from D:\code\anaconda3\envs\py38\lib\site-packages\pip (python 3.8)

确定都满足要求之后,输入

//安装最新gpu版本
pip intall tensorflow-gpu
//指定版本
pip intall tensorflow-gpu==2.1.0

测试安装:输入"import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

(py38) PS C:\Users\lenovo> python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2020-12-07 14:57:43.056616: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-07 14:57:43.056761: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-12-07 14:57:47.601373: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-07 14:57:47.634589: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5
coreClock: 1.2GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 245.91GiB/s
2020-12-07 14:57:47.636856: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-12-07 14:57:47.638105: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-12-07 14:57:47.664987: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-12-07 14:57:47.671588: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-12-07 14:57:47.673032: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-12-07 14:57:47.674327: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-12-07 14:57:47.675763: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-12-07 14:57:47.675822: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-12-07 14:57:47.676642: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-12-07 14:57:47.685301: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1d2cc13b480 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-12-07 14:57:47.685428: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-12-07 14:57:47.685904: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-07 14:57:47.686063: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
tf.Tensor(368.9865, shape=(), dtype=float32)
85904: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-07 14:57:47.686063: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]
tf.Tensor(368.9865, shape=(), dtype=float32)
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值