轉載請註明地址html
說明:本文檔參考自Caffe官網的安裝說明,http://caffe.berkeleyvision.org/installation.htmlpython
若是對安裝過程當中,須要用到的依賴不明,請自行百度其做用。Ubuntu系統的安裝請自行百度。 linux
1.安裝環境git
硬件:Intel E3 CPU,NVIDIA GTX960 GPU; 操做系統:Ubuntu14.04github
2.依賴安裝bash
接下來的安裝所有使用linux命令行操做網絡
(1)通用依賴 架構
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
(2)CUDA安裝app
可使用apt-get方式,或者去官網下載linux系統下的.run包進行離線安裝。因爲apt-get指令拿到的軟件包一般不是最新的,官網推薦使用.run包的方式進行離線安裝。工具
對於沒有GPU的同窗來講,能夠跳過這一步(以後在編譯源碼時配置CPU-ONLY)。
1)下載CUDA的.run包
地址:https://developer.nvidia.com/cuda-downloads
根據本身的OS和CPU架構選擇.run包並下載
2)退出桌面環境
使用鍵盤Ctrl+Alt+F1,系統退出桌面版,進入命令行模式。
注意:此時有些系統會遇到黑屏問題。解決方法:切回桌面版本(Ctrl+Alt+F7),修改/etc/default/grub文件中GRUB_CMDLINE_LINUX_DEFAULT的值爲nomodeset,更新grub(sudo update-grub),重啓電腦(或者重啓電腦,在啓動時進入grub設置中,將倒數第2行的roquiet splash 後面空格添加nomodeset,按F10啓動系統,而後再按ctrl+alt+F1發現能夠正常進入字符界面了)。
(安裝時遇到這個問題,我經過後一種方式解決)
3)退出X Windows桌面環境
sudo stop lightdm
4)安裝CUDA .run包
給.run包加上可執行權限:
chmod +x cuda_7.5.18_linux.run
執行.run包:
./cuda_7.5.18_linux.run
5)返回X Windows桌面環境
sudo start lightdm Ctrl+Alt+F7
6)cuDNN 安裝(可選)
若是使用 cuDNN 優化神經網絡, 須要安裝 cudnn-v5.0 以上版本。 該軟件的安裝很是簡單。
tar -xzvf cudnn-7.5-linux-x64-v5.0-ga.tgz cd cudnn-7.5-linux-x64-v5.0 sudo cp lib* /usr/local/cuda/lib64/ sudo cp cudnn.h /usr/local/cuda/include/
(3)BLAS
sudo apt-get install libatlas-base-dev
(4)Python
若是使用默認Python的方式進行Caffe開發,則須要安裝python開發包。
sudo apt-get install python-dev
(5)兼容性說明
操做系統 |
版本 |
兼容性說明 |
Ubuntu |
16.04 |
CUDA8是被須要的 |
14.04 |
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev |
|
12.04 |
須要手動安裝依賴(以下) |
若是是Ubuntu12.04,須要手動安裝兼容性依賴,以下:
wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz tar zxvf glog-0.3.3.tar.gz cd glog-0.3.3 ./configure make && make install # gflags wget https://github.com/schuhschuh/gflags/archive/master.zip unzip master.zip cd gflags-master mkdir build && cd build export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1 make && make install # lmdb git clone https://github.com/LMDB/lmdb cd lmdb/libraries/liblmdb make && make install
3.編譯Caffe源代碼並安裝
Caffe源碼支持make編譯,或者CMake方式進行編譯。編譯前請確認已經安裝好了gcc工具鏈(sudo apt-get install build-essential),若是使用CMake構建工程,請確認安裝好CMake。
(1)下載Caffe源碼
Git clone https://github.com/BVLC/caffe.git
或者在github官網搜索Caffe,選擇須要的分支而後Zip打包下載。
(2)Make編譯源碼
說明1:
Configure the build by copying and modifying the example Makefile.config for your setup. The defaults should work, but uncomment the relevant lines if using Anaconda Python.
如下爲命令行
cp Makefile.config.example Makefile.config # Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired) make all make test make runtest
說明2:
For CPU & GPU accelerated Caffe, no changes are needed.
For cuDNN acceleration using NVIDIA’s proprietary cuDNN software, uncomment the USE_CUDNN := 1 switch in Makefile.config. cuDNN is sometimes but not always faster than Caffe’s GPU acceleration.
For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config.
(3)CMake方式構建工程並編譯
根據須要能夠配置Makefile.config。
mkdir build cd build cmake .. make all make install make runtest
若是編譯沒有報Error,在runtest時一切OK,那麼說明安裝完成。能夠開始Caffe的第一個小例子MNIST。