posted on 2023-05-07 19:15 read(1186) comment(0) like(5) collect(2)
To get started with deep learning, the first thing to do is to build a deep learning environment. No matter you are a Windows user, a Mac user or an Ubuntu user, as long as the computer configuration allows, you can do deep learning. After all, Windows, Mac and Ubuntu systems can all build deep learning environments. Next, I will record the process of building a deep learning environment on the Windows system, so that I can archive it myself and provide a reference for everyone.
The main mode of this environment configuration is based on Anaconda+PyTorch (GPU version)+CUDA+cuDNN .
Anaconda official website: https://www.anaconda.com
Tsinghua University open source mirror download: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
Both websites can be downloaded, choose the version suitable for your computer to download That's it.
Click Download to download Anaconda.
Click the downloaded .exe file to install it. There is generally no major problem with the installation, just keep clicking next.
Here, if you are the only user on the computer, you can also choose Just Me; choosing All Users means that all users on this computer can use it, otherwise administrator privileges are required. Generally select All Users.
Note here: the folder must be empty, otherwise an error will be reported; secondly, Chinese characters should not appear in the folder name.
Then install it.
For case 1, open cmd and enter python -V to view the version that comes with anaconda;
for case 2, the version to view is the origin-python version before installing anaconda:
Right-click "My Computer"->Properties->Advanced System Settings->Environment Variables,
select the Path of the system variable to edit;
if you directly create an Anaconda folder on the D drive for installation, you can directly set the following four Add the path:
D:\Anaconda
D:\Anaconda\Scripts
D:\Anaconda\Library\ mingw-w64 \bin
D:\Anaconda\Library\bin
The format of the above path is: the drive letter you installed + your folder Name + the following constant content;
for example: if you installed Anaconda to a folder named Python in the E drive, then your format is
E:\Python\Library\name-w64\bin
The other three are similar, just modify the previous content.
1.4.1 Click Anaconda Navigator
to see if you enter the following page (the response time is long), and you can enter it smoothly: there
may be problems here: (If there is no flashback problem, you can directly jump to 1.4.2 to continue testing)
I am installing In anaconda, when I opened the above page for the first time, it was relatively smooth but an update prompt appeared. After clicking the update, I found that the Anaconda Navigator page could no longer be opened, or it would crash when opening this page, but there was no other place Any problem, only Anaconda Navigator can't open successfully.
The Anaconda flashback solution is as follows:
conda update anaconda-navigator
y
confirmation to upgrade. There will also be an option to choose whether to continue in the next few steps, just enter after checking y
.anaconda-navigator --reset
conda update anaconda-client
conda update -f anaconda-client
conda info
, and observe whether the following bunch of data is output: conda --version
, and observe whether the output version number: Operate in the Anaconda prompt:
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
Check if the channel is modified:
conda config --show channels
直接进NVIDIA官网:https://www.nvidia.cn/geforce/drivers/
在这里有GeForce驱动程序,立即下载,这是下载一个自动识别你电脑显卡的NVIDIA驱动,安装好之后记得注册一个账号并登录,然后在里面更新显卡驱动。
先点驱动程序,然后检查更新,就可以自动更新显卡驱动了。
更新完显卡驱动以后进Anaconda prompt的指令界面,输入nvidia-smi
,可以看见自己显卡的相关信息。
安装完NVIDIA以后我们还需要安装CUDA以及cuDNN,这两个是NVIDIA官方给出的便于深度学习计算的补丁
CUDA的安装之前我们先要看看相适配的版本,桌面空白处右键,打开NVIDIA控制面板,依次点击帮助-系统信息,在弹出的界面中选择组件:
在第三行我们可以看出我这台电脑要安装cuda11.6的版本,我们去下载cuda不可以高于这个版本,最好也别过低。
CUDA官网:https://developer.nvidia.com/cuda-downloads
下载相应版本即可。
下载完之后存放CUDA的文件夹会自动消失,后面可以从C盘找到相对应的路径。
下载地址:https://developer.nvidia.com/rdp/cudnn-download
下载的时候注意版号,一定要让cudnn和cuda的版号完全一样才可以。
下载好之后打开cudnn的压缩包,再打开cuda的目录(目录在图里):
可以看到cudnn有三个文件夹,把这些文件夹中的东西分别放进cuda对应的文件夹中就好。
至此cuda+cudnn就安装完成了,我们打开anaconda prompt,输入nvcc -V
来看看cuda信息:
经历了以上几步,我们终于配置好了显卡的驱动相关,接下来我们开始安装pytorch。
首先需要创建一个虚拟环境,然后进入我们创建好的的pytorch环境,输入以下命令:
创建名叫pytorch的虚拟环境:
conda create -n pytorch python=3.9
进入pytorch虚拟环境:
conda activate pytorch
然后安装pytorch:
conda install pytorch
之后等待solving environment,好了以后按照提示按y回车,就自动装好了
来验证一下我们装的是否有效。
即首先用conda activate pytorch
进入pytorch虚拟环境,然后在终端输入python进入python界面
分别输入
import torch
torch.cuda.is_available()
import torch以后回车无error,第二行指令返回的是true就大功告成
我用上面这种方法出现了问题,最后结果是false。所以我换了种方法,如下:
PyTorch官网:https://pytorch.org
官网界面往下拉
选择自己电脑的相关配置,然后在anaconda prompt中运行Run this Command里的代码:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
验证方法同上。
代码如下:
import torch
print(torch.__version__) #查看pytorch版本
print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
以上,我们就完成了windows下简单的深度学习环境配置。
首先下载自己python版本对应的pytorch包
通过如下方式,点击链接进入pytorch包下载路径:https://download.pytorch.org/whl/cu113
选择匹配自己python版本的torch、torchaudio和torchvision,下图中cu115代表匹配cuda11.5版本,cp39表示匹配python3.9版本,win就表示windows:
下载好这三个包后将其放置于site-packages目录下,即你平时安装包所在的位置,我的在C:\Users\25837\AppData\Roaming\Python\Python39\site-packages
,
接着在目录栏中直接cmd运行,然后将三个whl文件按次序分别安装,
pip install 名称
安装成功以后该目录下就会出现如下六个文件夹:
此时再重新进入python环境,输入如下代码检验环境是否配置成功:
import torch
print(torch.__version__) #查看pytorch版本
print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
此时,pytorch环境配置完成——但这里只是在python中配置完成,如果在conda中创建虚拟环境,这个虚拟环境中就不包含torch及其深度学习环境。
首先用管理员身份打开anaconda prompt,这样创建的虚拟环境会在anaconda安装目录下的envs中,否则创建的虚拟环境会因为没有权限而创建到C盘!!
创建完成之后,直接将前面利用pip安装的torch相关的六个文件夹复制到虚拟环境下的site-packages目录下,然后进行验证。
import torch
print(torch.__version__) #查看pytorch版本
print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
结果为Ture即环境配置成功!!
(经验帖里说这样直接复制过来就可以,但我试了之后并没有成功,不知道是什么原因呜呜呜!!)
经过几天的折腾之后,终于成功配置在虚拟环境中配置好了pytorch深度学习环境!!!
上面说到直接复制粘贴的方法对我不适用,所以我又重新换了新的方法。
即换镜像源,上面的操作其实是没有问题的,只不过不同的镜像源下载速度不同,有可能会出现中断的现象,于是pytorch就会安装不成功,所以此处的操作步骤依然是:
conda create -n pytorch python=3.9
建立好pytorch虚拟环境后,先进入pytorch虚拟环境然后安装pytorch
用以下命令进入pytorch环境:
conda activate pytorch
然后用下面的代码安装pytorch:
注:此处可以将11.3改为你安装的cuda对应的版本,比如我安装的cuda是11.5版本,复制完代码后直接将11.3改为11.5后运行即可 (不过不更改也不影响)
If the installation process here is interrupted or the installation is unsuccessful, you can change the mirror source and reinstall.
You can search for specific mirror sources by yourself.
(Because the mirror source I used is too slow, I don’t know which one is the fastest and best to use, so I don’t recommend it, anyway, just try a few more mirror sources and the download will always be successful! !)
(This is just to provide you with different ideas. For specific operations, you can refer to the above process or search by yourself. In short, try several methods and it will always succeed. And if it goes well, maybe the first installation will be successful. My first installation The time went smoothly, and this time the reinstallation will be abolished, and the boss stepped on a lot of pits.)
Also after the installation is complete, use the following code to check whether the installation is successful.
import torch
print(torch.__version__) #查看pytorch版本
print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
Author:kkkkkkkkkkdsdsd
link:http://www.pythonblackhole.com/blog/article/297/388c7a93d7844006b270/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!