深度学习环境安装

ubuntu18.04 Python3.6GPUOpencv4.1 环境的安装

python3 环境的基本安装库

版本控制

sudo apt-get install git gitk

python3 安装包

sudo apt-get install python3
sudo apt-get install python3-pip
sudo apt-get install python3-tk
sudo apt-get install ipython3
sudo apt-get install python3-dbg

sudo apt-get install python3-numpy
sudo apt-get install python3-scipy
sudo apt-get install python3-matplotlib
sudo apt-get  install python3-pandas
sudo -H pip3 install jupyter

opencv 源码安装

  • 去 opencv 官网下载 opencv4.1.0 的安装包或者 Github https://github.com/opencv/opencv.git 下载安装
  • 首先安装 opencv 的一些依赖库
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3-dev
  • 如果是压缩包, 首选解压源码,或者从Github 克隆,git clone https://github.com/opencv/opencv.git
  • 然后 cd opencv4.1.0
  • mkdir build
  • cd build
  • 切记 local .. 后面的两点
  • cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  • sudo make -j8
  • sudo make install
  • 基本上安装成功,可以去测试 pythn3.6c++ 的 opencv 环境

NVIDIA显卡安装

Ubuntu18.04 + cudn9.0 + cudnn7.05

显卡驱动安装

  • sudo vim /etc/modprobe.d/blacklist.conf
  • 然后在文件末尾加上以下两行
blacklist nouveau
options nouveau modeset=0
  • 保存退出
  • 输入下行代码可以查看电脑显卡信息
lspci | grep -i nvidia
  • 输入下行代码可以查找对应的驱动程序
ubuntu-drivers devices
  • 安装驱动
  • sudo apt-get install nvidia-driver-430
  • 一旦完成,即可重新启动系统
nvida-smi

gcc & g++ 降级

sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8
  • GCC 降级
  • 然后查看 /usr/bin/ 目录下
  • cd /usr/bin/
  • gcc 链接到了 gcc-7.2 需要将它改成为 gcc-4.8
ls -l gcc*
sudo mv gcc gcc.back
sudo ln -s gcc-4.8 gcc
  • g++ 链接到了 g+±7.2 需要将它改成为 g+±4.8
ls -l g++*
sudo mv g++ g++.back
sudo ln -s g++-4.8 g++
  • 查看 gcc & g++ 版本

cuda 安装

  1. 下载 cuda_9.0.176_384.81_linux.run
  2. 下载 cuda_9.0.176.1_linux.run
  3. 下载 cuda_9.0.176.2_linux.run
  4. 下载 cuda_9.0.176.3_linux.run
  5. 下载 cuda_9.0.176.4_linux.run

安装

sudo ./cuda_9.0.176_384.81_linux.run

Do you accept the previously read EULA?
accept/decline/quit: accept

You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: y

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n

Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
[ default is /usr/local/cuda-9.0 ]: y

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y

sudo ./cuda_9.0.176.1_linux.run

Do you accept the previously read EULA?
accept/decline/quit: accept

sudo ./cuda_9.0.176.2_linux.run

Do you accept the previously read EULA?
accept/decline/quit: accept

sudo ./cuda_9.0.176.3_linux.run

Do you accept the previously read EULA?
accept/decline/quit: accept

sudo ./cuda_9.0.176.4_linux.run

Do you accept the previously read EULA?
accept/decline/quit:accept

下载 cudnn7.05

sudo cp cuda/include/cudnn.h /usr/local/cuda/include 
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

查看安装是否成功

cat  /usr/local/cuda/version.txt
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 
sudo vim .bashrc

export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
 
export CUDA_HOME=/usr/local/cuda
source ~/.bashrc
  • 如果出现 pip3 安装比较慢,可以自己网上百度换以下国内的阿里云
  • 安装 python 版本的 tensorflow-gpu
pip3 install tensorflow-gpu==1.6.0
pip3 install keras==2.1.5
  • 安装 python 版本的 pytorch
pip3 install torch
pip3 install torchvision
  • python 的一些库
pip3 install h5py
pip3 install pillow
pip3 install visdom
...

tensorflow c++ 环境我接下来会详细介绍,感兴趣的请接下来关注。

你可能感兴趣的:(深度学习)