1 查看是否有GPU
下載和安裝 Python 3.8
下載和安裝 PyCharm
2 下載 Anaconda
https://www.anaconda.com/products/individual
https://repo.anaconda.com/archive/Anaconda3-2020.11-Windows-x86_64.exe
3 安裝 Anaconda
- Anaconda Navigator :用於管理工具包和環境的圖形用戶界面,后續涉及的眾多管理命令也可以在 Navigator 中手工實現。
- Jupyter notebook :基於web的交互式計算環境,可以編輯易於人們閱讀的文檔,用於展示數據分析的過程。
- qtconsole :一個可執行 IPython 的仿終端圖形界面程序,相比 Python Shell 界面,qtconsole 可以直接顯示代碼生成的圖形,實現多行代碼輸入執行,以及內置許多有用的功能和函數。
- Spyder :一個使用Python語言、跨平台的、科學運算集成開發環境。
4 打開Anaconda
Run as administrator
5 管理虛環境
創建虛擬環境,為自己的程序安裝單獨的虛擬環境.
創建一個名稱為 myenvpy38 的虛擬環境並指定python版本為3.8
conda create -n myenvpy38 python=3.8
environment location: E:\Eprogramfiles\Anaconda3\envs\myenvpy38
其中 E:\Eprogramfiles\Anaconda3\ 是anaconda的安裝路徑。
切換虛擬環境
切換到這個環境, 用activae命令,后面加上要切換的環境名稱
conda activate myenvpy38
查看所有的環境
如果忘記了名稱我們可以先用
conda env list
# To deactivate an active environment, use
# conda deactivate
conda env list
conda list
安裝第三方包
conda install packageName
或者
pip install packageName
卸載第三方包
conda remove packageName
或者
pip uninstall packageName
6 安裝PyTorch
以下步驟安裝不成功:
https://pytorch.org/
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
The following packages will be downloaded:
package | build
---------------------------|-----------------
cudatoolkit-10.2.89 | h74a9793_1 317.2 MB
libuv-1.40.0 | he774522_0 255 KB
lz4-c-1.9.3 | h2bbff1b_0 131 KB
mkl-service-2.3.0 | py38h196d8e1_0 47 KB
ninja-1.10.2 | py38h6d14046_0 247 KB
pillow-8.1.0 | py38h4fa10fc_0 664 KB
pytorch-1.7.1 |py3.8_cuda102_cudnn7_0 768.1 MB pytorch
torchaudio-0.7.2 | py38 2.7 MB pytorch
torchvision-0.8.2 | py38_cu102 7.2 MB pytorch
------------------------------------------------------------
Total: 1.07 GB
The following NEW packages will be INSTALLED:
blas pkgs/main/win-64::blas-1.0-mkl
cudatoolkit pkgs/main/win-64::cudatoolkit-10.2.89-h74a9793_1
freetype pkgs/main/win-64::freetype-2.10.4-hd328e21_0
intel-openmp pkgs/main/win-64::intel-openmp-2020.2-254
jpeg pkgs/main/win-64::jpeg-9b-hb83a4c4_2
libpng pkgs/main/win-64::libpng-1.6.37-h2a8f88b_0
libtiff pkgs/main/win-64::libtiff-4.1.0-h56a325e_1
libuv pkgs/main/win-64::libuv-1.40.0-he774522_0
lz4-c pkgs/main/win-64::lz4-c-1.9.3-h2bbff1b_0
mkl pkgs/main/win-64::mkl-2020.2-256
mkl-service pkgs/main/win-64::mkl-service-2.3.0-py38h196d8e1_0
mkl_fft pkgs/main/win-64::mkl_fft-1.2.0-py38h45dec08_0
mkl_random pkgs/main/win-64::mkl_random-1.1.1-py38h47e9c7a_0
ninja pkgs/main/win-64::ninja-1.10.2-py38h6d14046_0
numpy pkgs/main/win-64::numpy-1.19.2-py38hadc3359_0
numpy-base pkgs/main/win-64::numpy-base-1.19.2-py38ha3acd2a_0
olefile pkgs/main/noarch::olefile-0.46-py_0
pillow pkgs/main/win-64::pillow-8.1.0-py38h4fa10fc_0
pytorch pytorch/win-64::pytorch-1.7.1-py3.8_cuda102_cudnn7_0
six pkgs/main/win-64::six-1.15.0-py38haa95532_0
tk pkgs/main/win-64::tk-8.6.10-he774522_0
torchaudio pytorch/win-64::torchaudio-0.7.2-py38
torchvision pytorch/win-64::torchvision-0.8.2-py38_cu102
typing_extensions pkgs/main/noarch::typing_extensions-3.7.4.3-py_0
xz pkgs/main/win-64::xz-5.2.5-h62dcd97_0
zstd pkgs/main/win-64::zstd-1.4.5-h04227a9_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
torchaudio-0.7.2 | 2.7 MB | ######5 | 9%
pytorch-1.7.1 | 768.1 MB | | 0%
torchvision-0.8.2 | 7.2 MB | #2 | 2%
ninja-1.10.2 | 247 KB | ################################################################################## | 100%
mkl-service-2.3.0 | 47 KB | ################################################################################## | 100%
libuv-1.40.0 | 255 KB | ################################################################################## | 100%
pillow-8.1.0 | 664 KB | ################################################################################## | 100%
cudatoolkit-10.2.89 | 317.2 MB | ###3 | 4%
lz4-c-1.9.3 | 131 KB | ################################################################################## | 100%
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/win-64/torchaudio-0.7.2-py38.tar.bz2>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/win-64/pytorch-1.7.1-py3.8_cuda102_cudnn7_0.tar.bz2>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/win-64/torchvision-0.8.2-py38_cu102.tar.bz2>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
(myenvpy38) E:\Eprogramfiles\Anaconda3\myenv>
改變安裝策略:
1 查看顯卡對應的 CUDA
C盤搜索 nvcuda64.dll,右鍵,屬性
2 下載 cuda_11.0.3
https://developer.nvidia.com/cuda-toolkit-archive
http://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_451.82_win10.exe
文件3G左右,用迅雷下載比較快
3 安裝 cuda_11.0.3
默認都是必須安裝在C盤,超過4.5GB空間。自定義安裝的時候可以選擇路徑 e:\Eprogramfiles\cuda11\dev\,大部分文件仍然安裝到C盤了(C:\Program Files\NVIDIA GPU Computing Toolkit)
檢查是否安裝成功
e:\Eprogramfiles\cuda11\dev\bin>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Wed_Jul_22_19:09:35_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.0, V11.0.221
Build cuda_11.0_bu.relgpu_drvr445TC445_37.28845127_0
e:\Eprogramfiles\cuda11\dev\bin>
4 下載與 cuda 相應的 cudnn
https://developer.nvidia.com/rdp/cudnn-archive
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.0.4/11.0_20200923/cudnn-11.0-windows-x64-v8.0.4.30.zip
解壓 cudnn-11.0-windows-x64-v8.0.4.30.zip
前面安裝的cuda的路徑下也有這三個對應的文件夾(bin,include,lib),我們要做的就是用cudnn的三個文件夾覆蓋cuda中對應的三個文件夾.直接粘過去就行了!
測試是否將cudnn安裝好
首先進入CUDA的安裝路徑 -> extras -> demo_suite, E:\Eprogramfiles\cuda11\dev\extras\demo_suite 里面有兩個測試程序,一個是bandwidthTest.exe,一個是deviceQuery.exe
然后可以在demo_suite這個文件夾下打開cmd,運行那兩個exe,結果如下圖
E:\Eprogramfiles\cuda11\dev\extras\demo_suite>bandwidthTest.exe
[CUDA Bandwidth Test] - Starting...
Running on...
Device 0: GeForce GTX 1050
Quick Mode
Host to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12564.8
Device to Host Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 12848.8
Device to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 95124.9
Result = PASS
NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
E:\Eprogramfiles\cuda11\dev\extras\demo_suite>deviceQuery.exe
deviceQuery.exe Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 1050"
CUDA Driver Version / Runtime Version 11.0 / 11.0
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 4096 MBytes (4294967296 bytes)
( 5) Multiprocessors, (128) CUDA Cores/MP: 640 CUDA Cores
GPU Max Clock rate: 1493 MHz (1.49 GHz)
Memory Clock rate: 3504 Mhz
Memory Bus Width: 128-bit
L2 Cache Size: 524288 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: zu bytes
Total amount of shared memory per block: zu bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: zu bytes
Texture alignment: zu bytes
Concurrent copy and kernel execution: Yes with 5 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model)
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: No
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.0, CUDA Runtime Version = 11.0, NumDevs = 1, Device0 = GeForce GTX 1050
Result = PASS
5 安裝PyTorch
=====================================================
conda activate myenvpy38
鏡像源配置一下, 仍然特別慢
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
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
=====================================================
在下載的過程中下載torch1.7.1的時候比較慢,下載的過程中還會超時,故直接拷貝下載地址下載whl文件,安裝whl文件。
單獨下載:
https://download.pytorch.org/whl/torch_stable.html
https://download.pytorch.org/whl/cu110/torchvision-0.8.2%2Bcu110-cp38-cp38-win_amd64.whl
https://download.pytorch.org/whl/cu110/torch-1.7.1%2Bcu110-cp38-cp38-win_amd64.whl
https://download.pytorch.org/whl/torchaudio-0.7.2-cp38-none-win_amd64.whl
conda activate myenvpy38
pip --default-timeout=1000 install -U numpy -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip --default-timeout=1000 install -U matplotlib.pyplot -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip --default-timeout=1000 install -U matplotlib -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip --default-timeout=1000 install -U pandas -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip --default-timeout=1000 install -U sklearn -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip --default-timeout=1000 install -U typing-extensions -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
安裝有先后順序,先torch
E:\Eprogramfiles\Anaconda3\envs\myenvpy38>pip install "D:\software\torch-1.7.1+cu110-cp38-cp38-win_amd64.whl"
E:\Eprogramfiles\Anaconda3\envs\myenvpy38>pip install D:\software\torchaudio-0.7.2-cp38-none-win_amd64.whl
E:\Eprogramfiles\Anaconda3\envs\myenvpy38>pip install "D:\software\torchvision-0.8.2+cu110-cp38-cp38-win_amd64.whl"
REF
https://blog.csdn.net/qq_36306288/article/details/111243361
https://blog.csdn.net/weixin_42144294/article/details/111624608
https://www.cnblogs.com/chenyameng/p/14273935.html
https://blog.csdn.net/adong6561975/article/details/106548396/