Pages

Sunday, July 29, 2018

Caffe on Ubuntu Eclipse C C

Caffe on Ubuntu Eclipse C C


Purpose

After building Caffe framework, you can use Eclipse to develop and build your own application by including Caffe. Here is a article to teach you how to setup Eclipse for Caffe on Ubuntu14.04 and Eclipse C/C++.

Step 1: 
Open Eclipse, create a C++ project, and select Linux GCC toolchains.

Step2:
Go to "properties->C/C++ Build->Settings-> GCC C++ Compiler ->includes" to set Caffes include path. Add two paths to be included:
   to/your/path/caffe/include
   to/your/path/caffe/distribute/include

Notes: Whenever Caffe releases, need to run all build cmds


Step3:
  Go to "properties->C/C++ Build->Settings-> GCC C++ Linker ->Libraries" to set Caffes libray path.

Add the bellows to "Library search path(-L)"
     to/your/path/caffe/build/lib

Paste it to " include path(-l) "
     caffe


Step4: (Optional)
Because I didnt use GPU to compute, so I set CPU_ONLY=1 for preprocessor.
 




Step5: 
To let Linker find libcaffe.so , you need to specify libcaffe.so in Properties->C/C++ Build->Setting->GCC C++ Linker->Miscellaneous->Other objects

If you does not want specify libcaffe.so in Eclipse.
You can Set LD_LIBRARY_PATH to ~.bashrc to find libcaffe for linker
$ echo export LD_LIBRARY_PATH="to/your/path/caffe/build/lib/" > ~/.bashrc

In my case:
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib:/home/darrenl/developments/caffe/build/lib/"

Step6:
Add a *.cpp file and include caffe.hpp to build.

#include <caffe/caffe.hpp>
using caffe::Blob;
using caffe::Caffe;
using caffe::Datum;
using caffe::Net;
using caffe::shared_ptr;
using caffe::vector;
using caffe::MemoryDataLayer;
int main() {
Net<float> *caffe_net;
return 0;
}
You can refer to my source code:
$ git clone https://github.com/tzutalin/caffe_test.git

Build and Run
Build: Project-> Build Project  (ctrl + b)
Run: Run as Local C++ application (ctrl + F11)

Others:

You can refer to the blog to setup and build Caffe from scratch
http://tzutalin.blogspot.tw/2015/06/setup-caffe.html


visit link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.