ubuntu16.04 LTS安裝caffe

http://caffe.berkeleyvision.org/installation.html
在這裏插入圖片描述
部分模塊已安裝過,這些模塊只進行驗證。
先安裝一堆依賴:

$ 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 libgflags-dev libgoogle-glog-dev liblmdb-dev
$ sudo apt-get install libopenblas-dev 		(openblas和atlas的依賴庫不同)

CUDA

查看cuda版本:

$ nvcc -V

詳細例程見:https://docs.nvidia.com/cuda/archive/9.0/cuda-installation-guide-linux/index.html#compiling-examples

cuDNN

查看cuDNN版本:

$ cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2

詳細例程見:https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#verify

OPENBLAS

源代碼下載:https://github.com/xianyi/OpenBLAS

$ make
$ make install

添加搜索路徑:

export LD_LIBRARY_PATH=/opt/OpenBLAS/lib:$LD_LIBRARY_PATH

則在/opt/OpenBLAS可見。
例程:

//test_cblas_dgemm.c
#include <cblas.h>
#include <stdio.h>

void main()
{
  int i=0;
  double A[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};         
  double B[6] = {1.0,2.0,1.0,-3.0,4.0,-1.0};  
  double C[9] = {.5,.5,.5,.5,.5,.5,.5,.5,.5}; 
  cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans,3,3,2,1,A, 3, B, 3,2,C,3);

  for(i=0; i<9; i++)
  printf("%lf ", C[i]);
  printf("\n");
}

編譯:

$ gcc -o test_cblas_open test_cblas_dgemm.c -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran

如果沒有安裝gfortran,還要單獨安裝:

$ sudo apt install gfortran

執行:

$ ./test_cblas_open 
11.000000 -9.000000 5.000000 -9.000000 21.000000 -1.000000 5.000000 -1.000000 3.000000 

Boost

https://www.boost.org/users/history/version_1_67_0.html 下載源代碼並解壓
切換到解壓文件夾下,

$ ./bootstrap.sh
$ ./b2 install

添加搜索路徑

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

例程:

//example.cpp
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

jayne.txt :

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.
$ c++ -I /usr/local example.cpp -o example /usr/local/lib/libboost_regex.a
$ ./example < ./jayne.txt 
Will Success Spoil Rock Hunter?

OpenCV

我之前安裝了opencv-python-3.4.3,這裏沒有卸載,最後也通過了測試…爲了保險起見,最好還是卸載掉。有些博客提到舊的版本會和cuda8.0有不兼容的情況發生,我的cuda9.0和opencv-3.4.1編譯一次通過。
https://docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html
安裝cmake

$ sudo apt-get install cmake

安裝一堆依賴:

$ 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 python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

切到源代碼文件夾下,新建臨時文件夾:

$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make -j12

在“[96%]Built target opencv_perf_stitching”這一步有點慢,耐心等待即可。
測試:

$ cd ~
$ git clone https://github.com/opencv/opencv_extra.git
$ export OPENCV_TEST_DATA_PATH=~ 

切換到前面的build文件夾下運行測試文件:

$ ./bin/opencv_test_core

測試結果有一個未通過:

[----------] Global test environment tear-down
[==========] 10522 tests from 208 test cases ran. (478989 ms total)
[  PASSED  ] 10521 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] Core_globbing.accuracy

不要緊的 http://answers.opencv.org/question/23356/opencv-300-dev-core_globbing-failure/

CAFFE

http://caffe.berkeleyvision.org/installation.html#compilation
修改配置文件的時候一定要仔細仔細仔細!!!

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

編譯通過的config文件另開一篇放出吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章