深度学习入门——给Ubuntu系统安装CUDA、cuDNN、Anaconda、Tensorflow-GPU和pyTorch

1、安装CUDA、cuDNN、Anaconda、Tensorflow-GPU和pyTorch:

准备安装文件:

ubuntu@ubuntu:~$ ls
anaconda3                                    NVIDIA-Linux-x86_64-440.31.run
Anaconda3-5.1.0-Linux-x86_64.sh              snap
cuda_10.0.130_410.48_linux.run               公共的
cudnn_samples_v7                             模板
Downloads                                    视频
examples.desktop                             图片
libcudnn7_7.4.2.24-1+cuda10.0_amd64.deb      文档
libcudnn7-dev_7.4.2.24-1+cuda10.0_amd64.deb  下载
libcudnn7-doc_7.4.2.24-1+cuda10.0_amd64.deb  音乐
NVIDIA_CUDA-10.0_Samples                     桌面

安装后用 nvidia-smi 查询GPU参数:

ubuntu@ubuntu:~$ nvidia-smi
Sun Mar  1 20:24:23 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.31       Driver Version: 440.31       CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| 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 RTX 207...  Off  | 00000000:01:00.0  On |                  N/A |
| 40%   18C    P8     9W / 215W |    137MiB /  7979MiB |      7%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1020      G   /usr/lib/xorg/Xorg                           135MiB |
+-----------------------------------------------------------------------------+

安装后用 nvcc -V 查询CUDA版本:

ubuntu@ubuntu:~$ nvcc -V
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

安装CUDA后用CUDA自带的样例查询GPU和CUDA参数:

ubuntu@ubuntu:/usr/local/cuda/samples/1_Utilities/deviceQuery$ sudo ./deviceQuery
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce RTX 2070 SUPER"
  CUDA Driver Version / Runtime Version          10.2 / 10.0
  CUDA Capability Major/Minor version number:    7.5
  Total amount of global memory:                 7979 MBytes (8366784512 bytes)
  (40) Multiprocessors, ( 64) CUDA Cores/MP:     2560 CUDA Cores
  GPU Max Clock rate:                            1785 MHz (1.78 GHz)
  Memory Clock rate:                             7001 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 4194304 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:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1024
  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:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 3 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
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  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 = 10.2, CUDA Runtime Version = 10.0, NumDevs = 1
Result = PASS

在 Anaconda下创建虚拟环境来安装cuDNN, TesnorFlow 的 GPU 版,以及pyTorch等软件。

ubuntu@ubuntu:~$ source activate py36
(py36) ubuntu@ubuntu:~$ conda list
# packages in environment at /home/ubuntu/.conda/envs/py36:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_tflow_select             2.1.0                       gpu  
absl-py                   0.9.0                    py36_0  
astor                     0.8.0                    py36_0  
blas                      1.0                         mkl  
c-ares                    1.15.0            h7b6447c_1001  
ca-certificates           2020.1.1                      0  
certifi                   2016.2.28                py36_0  
cudatoolkit               10.0.130                      0  
cudnn                     7.6.5                cuda10.0_0  
cupti                     10.0.130                      0  
gast                      0.2.2                    py36_0  
google-pasta              0.1.8                      py_0  
grpcio                    1.14.1           py36h9ba97e2_0  
h5py                      2.10.0           py36h7918eee_0  
hdf5                      1.10.4               hb1b8bf9_0  
intel-openmp              2020.0                      166  
keras-applications        1.0.8                      py_0  
keras-preprocessing       1.1.0                      py_1  
libgcc-ng                 9.1.0                hdf63c60_0  
libgfortran-ng            7.3.0                hdf63c60_0  
libprotobuf               3.11.4               hd408876_0  
libstdcxx-ng              9.1.0                hdf63c60_0  
markdown                  3.1.1                    py36_0  
mkl                       2020.0                      166  
mkl-service               2.3.0            py36he904b0f_0  
mkl_fft                   1.0.15           py36ha843d7b_0  
mkl_random                1.1.0            py36hd6b4f25_0  
numpy                     1.18.1           py36h4f9e942_0  
numpy-base                1.18.1           py36hde5b4d6_1  
openssl                   1.0.2u               h7b6447c_0  
opt_einsum                3.1.0                      py_0  
Pillow                    7.0.0                     <pip>
pip                       20.0.2                    <pip>
pip                       9.0.1                    py36_1  
protobuf                  3.11.4           py36he6710b0_0  
python                    3.6.2                         0  
readline                  6.2                           2  
scipy                     1.4.1            py36h0b6359f_0  
setuptools                36.4.0                   py36_1  
six                       1.14.0                   py36_0  
sqlite                    3.13.0                        0  
tensorboard               1.15.0             pyhb230dea_0  
tensorflow                1.15.0          gpu_py36h5a509aa_0  
tensorflow-base           1.15.0          gpu_py36h9dcbed7_0  
tensorflow-estimator      1.15.1             pyh2649769_0  
tensorflow-gpu            1.15.0               h0d30ee6_0  
termcolor                 1.1.0                    py36_1  
tk                        8.5.18                        0  
torch                     1.4.0+cu92                <pip>
torchvision               0.5.0+cu92                <pip>
webencodings              0.5.1                    py36_1  
werkzeug                  0.16.1                     py_0  
wheel                     0.29.0                   py36_0  
wrapt                     1.11.2           py36h7b6447c_0  
xz                        5.2.4                h14c3975_4  
zlib                      1.2.11               h7b6447c_3

参考:

https://blog.csdn.net/feifeiyechuan/article/details/94451052

https://blog.csdn.net/H_O_W_E/article/details/77370456

 

2、使用Anaconda创建虚拟环境:

查看已安装的虚拟环境:

conda info -e

指定Python版本创建虚拟环境:

conda create --name py36 python=3.6

查看虚拟环境安装过的依赖包:

conda list -n py36

给虚拟环境安装依赖包:

conda install -n py36 cudnn

激活虚拟环境:

source activate py36

退出虚拟环境:

source deactivate 

给虚拟环境安装OpenCV-Python:

conda install -n py36 --channel https://conda.anaconda.org/menpo opencv3

参考:

https://zhuanlan.zhihu.com/p/44398592

https://zhuanlan.zhihu.com/p/55739118

https://zhuanlan.zhihu.com/p/94744929

https://blog.csdn.net/mjl960108/article/details/80141467

上一篇:win10系统极简安装Tensorflow2.1—gpu版本流程


下一篇:jquery实现点击页面其他地方隐藏指定元素