layout | title | categories | tags | date | description | |||
---|---|---|---|---|---|---|---|---|
post
|
深度学习:玩转caffe之安装
|
|
|
2017-01-22 12:20:20 -0800
|
Caffe install in Ubuntu
|
Caffe安装初探
引言
做深度学习,没用玩过深度学习框架caffe就有点说不过去了。虽然自己的小机器显卡计算能力很弱,但是希望在cuda上跑caffe的心却没有停止过。从ubuntu12.04一直折腾到16.04,cuda从6.5也release到了8.0,中间走过的弯路很多。
- cuda与系统的适配能力问题
- ubuntu系统的问题
- caffe的框架的问题 经过这几年的发展,现在caffe的安装已经变得异常简单便捷。在此记录一下曾经的坑。 建议: 直接在机器上安装linux进行下面操作,要是在虚拟机里整,几乎没有什么戏,而且会把你给整疯的。
安装BLAS
BLAS 可以通过mkl atlas openblas等实现,性能比较 发现这个mkl是不错的,但是要收费 最后选择默认的Atlas
********** Important Install Information: CPU THROTTLING *********** Architecture configured as Corei2 (27) /tmp/ccp8Kkgo.o: In function ATL_tmpnam': /home/charles/Repo/ATLAS//CONFIG/include/atlas_sys.h:224: warning: the use of
tmpnam' is dangerous, better use `mkstemp'
Clock rate configured as 800Mhz
Maximum number of threads configured as 4
probe_pmake.o: In function `ATL_tmpnam':
/home/charles/Repo/ATLAS//CONFIG/include/atlas_sys.h:224: warning: the use of `tmpnam` is dangerous, better use `mkstemp`
Parallel make command configured as '$(MAKE) -j 4'
CPU Throttling apparently enabled!
It appears you have cpu throttling enabled, which makes timings
unreliable and an ATLAS install nonsensical. Aborting.
See ATLAS/INSTALL.txt for further information
xconfig exited with 1
******************************* Solution *************************** use ubuntu main software source switch to root admin
apt-get install gnome-applets cpufreq-selector -g performance -c 0
sudo apt-get install libatlas-base-dev
安装BOOST
- preinstall boost should install following software
- compile the source code 下载源代码,当前最新版本为version 1.60
wget http://downloads.sourceforge.net/project/boost/boost/1.60.0/boost_1_60_0.tar.gz
unpacking boost 1.60.tar.gz
source boot
./b2
./b2 install --prefix=/usr/local
#include <boost/lexical_cast.hpp>
#include <iostream>
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.12");
std::cout<<a<<std::endl;
std::cout<<b<<std::endl;
return 0;
}
或者直接apt-get install libboost-all-dev
从7.5之后安装的方法简单得多
sudo apt-get --purge remove nvidia-*
到https://developer.nvidia.com/cuda-downloads下载对应的deb文件 到deb的下载目录下
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
sudo apt-get update
sudo apt-get install cuda
sudo reboot
完成,cuda和显卡驱动就都装好了;其他的什么都不用动 而网上大部分中文和英文的参考教程都是过时的,折腾几个小时不说还容易装不成。
查看机器参数是否满足CUDA计算的最低要求
lspci | grep -i nvidia
01:00.0 3D controller: NVIDIA Corporation GF117M [GeForce 610M/710M/820M / GT 620M/625M/630M/720M] (rev a1)
参照nvidia 往年发布的gpus 我的机器为Compute Capability 2.1,是可以使用CUDA加速的。: )
不是所有Nvida显卡都支持cuDNN的
折腾了很久的cuDNN安装,后来才发现是自己的显卡太low了,不支持cuDNN,因为Compute Capability 才2.1,要支持cuDNN, Capability >= 3.0,查看自己显卡的计算能力
install cuDNN
PREREQUISITES CUDA 7.0 and a GPU of compute capability 3.0 or higher are required. Extract the cuDNN archive to a directory of your choice, referred to below as .Then follow the platform-specific instructions as follows.
LINUX
cd <installpath>
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
Add to your build and link process by adding -I to your compile line and -L -lcuDNN to your link line.
WINDOWS
Add to the PATH environment variable.
In your Visual Studio project properties, add to the Include Directories and Library Directories lists and add cuDNN.lib to Linker->Input->Additional Dependencies.
非GPU的自动安装脚本
pyCaffe编译安装
- 首先要编译caffe成功,make pycaffe也成功
- 使得pycaffe可以被访问到, set
PYTHONPATH=$PYTHONPATH:/path/to/caffe/python
- install dependencies python package.在python文件夹下面有requirements.txt文件,列出了所有有关的python package.
pip install -r requirements.txt
Note 这里一定要弄明白,默认情况下是使用python2.x的,如果你使用python3.x的话,请安装python3-pip,使用pip3进行安装,
综合一个安装cuda的教程
可以参考https://gwyve.github.io/博客,为了方便把gwyve的cuda