In recent years, the Pytorch deep learning framework has become more and more popular among deep learning developers due to its simple network structure and low entry barrier. It is different from TensorFlow in that Pytorch is a dynamic framework and does not need to be set up at the beginning. The architecture can be modified while debugging during operation, while TensorFlow is the opposite. The advantage of this is that developers do not need to clarify the structure of the network built at the beginning, and can slowly learn to find a more suitable structure, just like in the building Engineers on site visits on the construction site, workers will come over every time they build a wall and ask what to do next, and TensorFlow is like an architect drawing drawings in an office, designing the structure of the entire building before construction, and when designing No one will bother, of course, the efficiency is higher than Pytorch.
Environment: Ubuntu16.04
Graphics card: NVIDIA GTX970
Since we need to use CUDA to accelerate the training process in Pytorch, the first step is to install the graphics driver to prepare for the installation of CUDA.
ctrl + alt + f1
#Enter the command line mode to stop using the graphics card sudo service lightdm stop
#Close the graphical interface sudo apt-get remove --purge nvidia*
#Remove the old driver sudo apt-get update
sudo apt-get install dkms build-essential linux-headers-generic
#install dependencysudo vim /etc/modprobe.d/blacklist-nouveau.conf
#disable nouveau, enter the following sudo update-initramfs -u
ctrl + alt + f1
#Enter the command line mode again sudo service lightdm stop
#Close the graphical interface again sudo service lightdm stop
sudo ./NVIDIA-Linux-x86_64-384.98.run -no-opengl-files
#install driver sudo service lightdm start
#Start the graphical interface cat /proc/driver/nvidia/version
#Test drive sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
#install deb package sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
#apt adds the public key required to install CUDA sudo apt-get update
sudo apt-get install cuda
#apt install CUDA export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
#Add environment variables export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
#64-bit system needsnvcc -V
cuDNN is a tool library used by NVIDIA to accelerate deep neural network training. Although it is not necessary, it is better to install it for easier use in the future.
runtime library
sudo dpkg -i libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
#install deb packageThis article uses conda to install Pytorch, readers can also choose pip, but the author failed to install twice with pip, and finally chose conda, which is also a python package management tool, but Pytorch officially recommends conda, which seems to be more dependent on installation .
bash Anaconda.sh
source ~/anaconda3/etc/profile.d/conda.sh
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
#Add the mirror source of Tsinghua University to speed up conda download conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
#Specially add Pytorch mirror source. Since Pytorch is launched by Facebook, it is not possible to directly access its whl file in China Yes, need to use the mirror source of Tsinghua University conda install pytorch
python conda install torchvision
Recommended Posts