折腾了许久,参考了很多大神的资料,把自己安装好的步骤完完全全的写下来,感觉还不错。
环境是使用的linux mint 18.3,mint linux的桌面环境非常不错,能够自动帮你安装好nvidia驱动,能够省去不少事。之前的anaconda用的很方便,因为有些在linux环境下运行的程序没办法在spyder上运行,(如Fast-Rcnn),所以只能摸索着安装普通的教程。
1.安装虚拟python的环境sudo apt-get install python3-pip python3-dev python-virtualenv
sudo apt-get install virtualenv
2.创建虚拟的python3环境(后面要加入目录【home目录下的一个文件夹就ok】)
virtualenv --system-site-packages -p python3 py3
3.激活虚拟环境(使用source进入虚拟环境:)
source py3/bin/activate
4.确保pip版本大于8.1,重装一遍新的easy_install -U pip
5.安装tensorflow(pip和pip3安装的版本不一样)
tensorflow 1.6需要cuda 9.0,驱动也要9.0的驱动
tensorflow 1.4需要cuda 8.0 安装cudnn5.1后,提示需要cudnn6.0
tensorflow 1.2需要cudnn 5.0
因此:tensorflow 1.2+cuda8.0+cudnn 5.0
pip install --upgrade tensorflow # for Python 2.7
pip3 install --upgrade tensorflow # for Python 3.n
pip install --upgrade tensorflow-gpu # for Python 2.7 and GPU
pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU
pip uninstall PackageName卸载
安装指定版本:pip3 install tensorflow-gpu==1.2
6.退出虚拟的环境:deactivate
8.安装cudasudo bash **.run
添加环境变量
gedit ~/.bashrc
export PATH="$PATH:/usr/local/cuda-8.0/bin"
export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"
source ~/.bashrc
卸载cudacd /usr/local/cuda/binsudo ./uninstall_cuda_7.5.pl
检查nvcc -V
9.安装cudnn
cudnn v5tar xvzf cudnn-8.0-linux-x64-v5.1.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64
sudo chmod a+r /usr/local/cuda-8.0/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*
10.安装opencv 3.4
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ cd opencv-3.1.0$ mkdir build
$ cd opencv-3.1.0/build$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make -j4
$ sudo make install
11.安装caffe (注意:在此选择的是安装python 3.5 版本的,默认的参数是2.7的,需要修改makefile文件和makefile.config文件)
安装环境$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
$ sudo apt-get install --no-install-recommends libboost-all-dev
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libhdf5-serial-dev
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
下载caffe
git clone https://github.com/BVLC/caffe.git
cp Makefile.config.example Makefile.config
Makefile.config修改:(python3.5环境的路径是刚刚安装的)
WITH_PYTHON_LAYER := 1
USE_CUDNN := 1
OPENCV_VERSION := 3
PYTHON_INCLUDE :=/home/hjl/py3/include/python3.5m \
/home/hjl/py3/lib/python3.5/site-packages/numpy/core/include
PYTHON_LIB := /home/hjl/py3/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
Makefile修改: (/usr/lib/x86_64-linux-gun/里面的)
PYTHON_LIBRARIES ?= boost_python-py35 python3.5m
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
编译:make pycaffe
make all -j4 #cpu4核同时工作
make test
make runtest
测试:
sudo ./data/mnist/get_mnist.sh
sudo ./examples/mnist/create_mnist.sh
sudo ./examples/mnist/train_lenet.sh
网友评论