之前装的时候每次都偷懒不做记录,然后要装新的时候就又要找半天教程,这次老老实实记录一下。
1.安装 nvidia驱动
先查一下驱动http://www.nvidia.com/Download/index.aspx?lang=en-us)本机的话是384
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-384
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
2.安装cuda
从官网下载https://developer.nvidia.com/cuda-80-ga2-download-archive 这里选的是直接下离线版 担心网速原因他有两个包 一大一小
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
安装完毕后,再声明一下环境变量,并将其写入到~/.bashrc的尾部:
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
#设置环境变量和动态链接库,在命令行输入:
sudo gedit /etc/profile
#在打开的文件末尾加入:
export PATH = /usr/local/cuda/bin:$PATH
sudo gedit /etc/ld.so.conf.d/cuda.conf
#打开的文件中添加如下语句
/usr/local/cuda/lib64
#链接立即生效
sudo ldconfig
测试cuda的Samplescd
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuerymakesudo
./deviceQuery
显示如下,表示cuda装好
image
3.安装anaconda2
直接bash ×××.sh执行,然后一路enter就好了。(不要自己作 加个sudo后面要用的话就各种报权限不够,千万不要用root权限去搞,不然之后再装包只能用root了)
由于网速原因,更换为清华的源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
之后会自动在用户根目录生成“.condarc”文件,Ubuntu环境下路径为~/.condarc,Windows环境下路径为C:\用户\your_user_name.condarc.不要的话删掉就好。
conda 一些常用命令
conda env list #查看已安装的python 环境
coda create -n caffe python=2.7 #创建一个名字叫caffe 的python环境版本为python2.7
4.安装caffe
https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide
#安装依赖项
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
#安装OpenCV-2.4
sudo apt-get install -y libopencv-dev
#安装某Python包
sudo apt-get install -y python-numpy python-scipy(这里不这样install
numpy,编译的时候会报错如下,找不到numpy)
image.png
从GitHub上下载caffe,或者使用git clone
cp Makefile.config.example Makefile.config
gedit Makefile.config (修改Python的路径 自己用的是anaconda python-include 和python-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**
#自己之前已经创建了 cuda到cuda8.0的链接
cd python
#安装需要的包
for req in $(cat requirements.txt); do pip install $req; done
#返回上级目录
cd ../
gedit ./Makefile
#将如下句子改为
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
*NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)*
在 CMakeLists.txt里添加
# ---[ Includes
set(${CMAKE_CXX_FLAGS} "-D_FORCE_INLINES ${CMAKE_CXX_FLAGS}")
#开始编译
make all -j16
make test -j16
make runtest -j16
此时出现错误
.build_release/tools/caffe: error while loading shared libraries: libhdf5_hl.so.100: cannot open shared object file: No such file or directory
Makefile:534: recipe for target 'runtest' failed
make: *** [runtest] Error 127
没有libhdf5_hl.so.100这个文件,然后查询自己有啥
cd /usr/lib/x86_64-linux-gnu
find find libhd*
发现自己有的是
image.png
sudo ln -s libhdf5_serial_hl.so.10 libhdf5_hl.so.100
sudo ldconfig
此时make runtest -j16 重新出现错误
.build_release/tools/caffe: error while loading shared libraries: libhdf5.so.101: cannot open shared object file: No such file or directory
Makefile:534: recipe for target 'runtest' failed
make: *** [runtest] Error 127
如法炮制
sudo ln -s libhdf5_serial.so.10 libhdf5.so.101
sudo ldconfig
然后
make runtest -j16
make pycaffe
#添加caffe至环境变量,这样Python就可以直接import啦
gedit /.bashrc
export PYTHONPATH=/home/caffe-master/python:$PYTHONPATH
至此,caffe安装完毕。跑个mnist试一下
http://caffe.berkeleyvision.org/gathered/examples/mnist.html
cd $CAFFE_ROOT
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh #下载数据集并且转化为lmdb格式
./examples/mnist/train_lenet.sh #训练网络 其中在solver.prototxt里面指定网络结构,迭代次数,优化方式,初始化方式等
./build/tools/caffe test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -gpu 0 -iterations 100 #测试其中itreation为迭代次数,和batchsize和测试集的个数有关系,就是要cover测试集
5.安装TensorFlow
只要一句话:
conda install tensorflow-gpu
换了清华的源速度果真飞了 附带装了很多依赖,竟然有cudnn还是6的版本
image.png
主要参考:
http://blog.csdn.net/autocyz/article/details/52299889 用于NVIDIA驱动和CUDA
https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide 安装caffe
后记
之后重新编译caffe 发现报错:
对‘google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)’未定义的引用
就是protobuf的问题,然后找了一圈发现,恩,是因为自己在anaconda里面又装了protobuf3.4的版本,冲突了。所以,一定要把这些环境隔离开来。不要放在一起。 所以卸载 conda uninstall protobuf conda uninstall libprotobuf
编译ssd的时候报错:
.build_release/lib/libcaffe.so:对‘boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const’未定义的引用
.build_release/lib/libcaffe.so:对‘boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const’未定义的引用
自己已经安装了boost了,百度之 通过https://github.com/rbgirshick/fast-rcnn/issues/52解决
在makefile 的263行 添加 boost_regex 即修改为 LIBRARIES += boost_thread stdc++ boost_regex 就好了
重装tf
conda create -n tf27 python=2.7
source activate tf27
which python (可以查看当前使用的是哪个Python)
conda install tensorflow-gpu
pytorch 安装
按照官网的命令https://pytorch.org/get-started/previous-versions/
conda install pytorch=0.4.1 cuda90 -c pytorch
报错
HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/linux-64/pytorch
是指定了pytorch 这个包的安装源,然后又访问不上 所以去掉-c pytorch 就可以了,愉快的使用清华源









网友评论