ubuntu-tensorflow-caffe-源码安装

tensorflow-1.4.0-rc0 CUDA-8.0 cudnn-6.0 bazel-0.5.4
cuda

sudo dpkg -i cuda-repo-ubuntu1604-8-0-rc_8.0.27-1_amd64​.deb
sudo apt-get update
sudo apt-get install cuda​

gcc降版本

sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

cudnn

tar xvzf cudnn-8.0-linux-x64-v5.1-ga.tgz
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*

环境变量

sudo gedit ~/.bash_profile

末尾加入

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda

终端生效

source ~/.bash_profile #使更改的环境变量生效

其他依赖

sudo apt-get install python-pip python-dev

bazel
JDK8安装

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer 

正在连接 edelivery.oracle.com (edelivery.oracle.com)|184.85.123.124|:443… 失败:无效的参数。要翻墙
验证java版本:java -version
bazel安装

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee/etc/apt/sources.list.d/bazel.list
sudo apt install curl
curl http://storage.googleapis.com/bazel-apt/doc/apt-get.pub.pgb | sudo apt-get add -
sudo apt-get update
sudo apt-get upgrade bazel

其他依赖包

sudo apt-get install python-numpy swig python-dev python-wheel

tensorflow安装

sudo apt-get install git
git clone https://github.com/tensorflow/tensorflow
cd ~/tensorflow #切换到tensorflow文件夹
./configure #执行configure文件

创建pip

bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg  
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-rc0-cp27-cp27mu-linux_x86_64.whl  

编译安装tensorflow GPU版本时报错:Cannot find libdevice.10.bc under /usr/local/cuda-8.0
解决办法为:
将/usr/local/cuda-8.0/nvvm/libdevice/libdevice.compute_50.10.bc复制一份至/usr/local/cuda-8.0/, 改为libdevice.10.bc
opencv-3.4.0

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8 
sudo make install
pkg-config --modversion opencv 通过查看 opencv 版本验证是否安装成功

caffe-1.0
下载caffe

git clone https://github.com/bvlc/caffe.git 
cd caffe/ 

Makefile.config

mv Makefile.config.example Makefile.config
gedit Makefile.config
将#USE_CUDNN := 1修改成:USE_CUDNN := 1#OPENCV_VERSION := 3 修改为:OPENCV_VERSION := 3
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/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 /usr/lib/x86_64-linux-gnu/hdf5/serial       

Makefile

将:
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

编辑/usr/local/cuda/include/host_config.h

将
#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
改为
//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!

python

cd python 
for req in $(cat requirements.txt);do sudo pip install $req; done
cd ..
make pycaffe -j8

编译

 make all -j8
 make test
 make runtest

错误
1.解决 sudo apt-get install protobuf-c-compiler protobuf-compiler
make: protoc:命令未找到
Makefile:638: recipe for target ‘.build_release/src/caffe/proto/caffe.pb.cc’ failed
2.解决 sudo apt-get install libprotobuf-dev
fatal error: google/protobuf/stubs/common.h: 没有那个文件或目录
3.解决 sudo apt-get install –no-install-recommends libboost-all-dev
fatal error: boost/shared_ptr.hpp: 没有那个文件或目录
4.解决 sudo apt-get install libgflags-dev
fatal error: gflags/gflags.h: 没有那个文件或目录
5.解决 sudo apt-get install libgoogle-glog-dev
fatal error: glog/logging.h: 没有那个文件或目录
6.解决 sudo apt-get install libblas-dev
fatal error: cblas.h: 没有那个文件或目录
7.解决 sudo apt-get install liblmdb-dev
fatal error: lmdb.h: 没有那个文件或目录
8.解决 sudo apt-get install libleveldb-dev
fatal error: leveldb/db.h: 没有那个文件或目录
9.解决 sudo apt-get install libhdf5-serial-dev
fatal error: hdf5.h: 没有那个文件或目录
10. sudo apt-get install libsnappyl-dev libatlas-base-dev
/usr/bin/ld: 找不到 -lsnappy
/usr/bin/ld: 找不到 -lcblas
/usr/bin/ld: 找不到 -latlas
11.未定义的引用 gcc 4.9->5.0

猜你喜欢

转载自blog.csdn.net/weixin_38900691/article/details/80268821