記錄一下在ubuntu14.04上用clion調(diào)用caffe相關(guān)庫的步驟。
新建一個project枫振,由于clion使用的是cmake,所以在cmakelist.txt里面添加相應(yīng)的頭文件和庫文件搜索路徑(/home/leo/caffe是我caffe的根目錄):
cmake_minimum_required(VERSION 3.7)
project(caffe_learning)
set(CMAKE_CXX_STANDARD 11)
include_directories(/home/leo/caffe/include /usr/local/cuda/include /usr/include/opencv /usr/include/boost /home/leo/caffe/.build_debug/src)
find_library(caffe /home/leo/caffe/build/lib)
link_libraries("/home/leo/caffe/.build_debug/lib/libcaffe.so" "/usr/local/lib/libglog.so")
set(SOURCE_FILES main.cpp)
add_executable(caffe_learning ${SOURCE_FILES})
在main.cpp寫一些代碼測試:
//
// Created by leo on 17-5-11.
//
#include <vector>
#include <iostream>
#include "caffe/blob.hpp"
using namespace std;
using namespace caffe;
int main(void){
Blob<float> a;
cout << "size: " << a.shape_string() << endl;
a.Reshape(1,2,3,4);
cout << "size: " << a.shape_string() << endl;
float *p = a.mutable_cpu_data();
for(int i = 0; i < a.count(); ++i){
p[i] = i;
}
for(int u = 0; u < a.num(); ++u){
for(int v = 0; v < a.channels(); ++v){
for(int w = 0; w < a.height(); ++w){
for(int z = 0; z < a.width(); ++z){
cout << a.data_at(u,v,w,z) << endl;
}
}
}
}
return 0;
}
輸出:
size: (0)
size: 1 2 3 4 (24)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
當(dāng)然我這只是做了最基本的測試萤彩,不能保證還會不會缺其他庫和頭文件蒋得,具體添加方式看之后報什么錯,再具體往cmakelist.txt添加即可乒疏。
有問題歡迎留言,一起探討