Tutorial to use caffe as a library(C++, Ubuntu)

1,685 views
Skip to first unread message

Qingkai Lu

unread,
Feb 25, 2016, 11:47:51 AM2/25/16
to Caffe Users
I am trying to use caffe in my own c++ project under Ubuntu. Does anyone know a tutorial about how use caffe as a library in your own c++ project? I didn't see such a tutorial on the caffe website. Thank you in advance for any help!

Felix Abecassis

unread,
Feb 25, 2016, 12:55:20 PM2/25/16
to Caffe Users

Qingkai Lu

unread,
Feb 25, 2016, 3:57:54 PM2/25/16
to Caffe Users
The classification.bin  is within the caffe  library. I want to use the caffe as an extern library for my own c++ project. 

Felix Abecassis

unread,
Feb 25, 2016, 4:24:43 PM2/25/16
to Caffe Users
It's easy to extract the classification code, you just need the headers and libcaffe.so

Felix Abecassis

unread,
Feb 26, 2016, 7:37:28 PM2/26/16
to Caffe Users
You might be interested in this demo that I just published:
https://github.com/NVIDIA/gpu-rest-engine

This should be similar to what you are trying to do.

Qingkai Lu

unread,
Feb 28, 2016, 11:36:54 PM2/28/16
to Caffe Users
Tried to add the headers and libcaffe.so, but it doesn't work. 

Get these errors:

/tmp/ccBU4IJg.o: In function `caffe::Caffe::set_mode(caffe::Caffe::Brew)':
extract_features.cpp:(.text._ZN5caffe5Caffe8set_modeENS0_4BrewE[_ZN5caffe5Caffe8set_modeENS0_4BrewE]+0xc): undefined reference to `caffe::Caffe::Get()'
/tmp/ccBU4IJg.o: In function `caffe::Datum::clear_data()':
extract_features.cpp:(.text._ZN5caffe5Datum10clear_dataEv[_ZN5caffe5Datum10clear_dataEv]+0x17): undefined reference to `google::protobuf::internal::kEmptyString'
/tmp/ccBU4IJg.o: In function `int feature_extraction_pipeline<float>(int, char**)':
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x3a): undefined reference to `google::InitGoogleLogging(char const*)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x6d): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x7c): undefined reference to `google::LogMessage::stream()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x9a): undefined reference to `google::LogMessage::~LogMessage()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x11e): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x12d): undefined reference to `google::LogMessage::stream()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x14b): undefined reference to `google::LogMessage::~LogMessage()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x211): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x220): undefined reference to `google::LogMessage::stream()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x22f): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x24f): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x25e): undefined reference to `google::LogMessage::stream()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x28c): undefined reference to `google::LogMessage::~LogMessage()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x299): undefined reference to `caffe::Caffe::SetDevice(int)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x2c5): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x2d4): undefined reference to `google::LogMessage::stream()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x2f2): undefined reference to `google::LogMessage::~LogMessage()'
extract_features.cpp:(.text._Z27feature_extraction_pipelineIfEiiPPc[_Z27feature_extraction_pipelineIfEiiPPc]+0x3e5): undefined reference to `caffe::Net<float>::Net(std::string const&, caffe::Phase, caffe::Net<float> const*)'

Any hint? Thank you. 

Qingkai Lu

unread,
Feb 28, 2016, 11:37:52 PM2/28/16
to Caffe Users
Thank you. I will have a look of this demo.

Jan C Peters

unread,
Feb 29, 2016, 3:24:16 AM2/29/16
to Caffe Users
You need to add the google protobuf library too (-lprotobuf).

Jan

Jan C Peters

unread,
Feb 29, 2016, 3:25:01 AM2/29/16
to Caffe Users
Oh, my bad, this is not the protobuf library, but the logging framework glog that needs to be added.

Jan
Reply all
Reply to author
Forward
0 new messages