cpp Code for inference using DetectNet

174 views
Skip to first unread message

sz Mousavi

unread,
Oct 1, 2016, 12:08:22 PM10/1/16
to DIGITS Users
Hi everyone,

I'm trying to write a cpp code to perform inference with DetectNet. Up to this point I've been using python for this (by modifying example.py from Classification Example and it worked fine. Now for some reasons I have decided to move to cpp. I have built nv-caffe from source (the version is 0.15.13) and for compiling the code I'm using a makefile like this:

 
CXX=g++

CFLAGS
= -c -Wall -std=c++0x -g3 -Ofast -msse2  

#include directories
INCLUDE
= -I. -I/usr/local/cuda/include -I/path/to/nv-caffe/include/ -I/path/to/nv-caffe/src/

#library paths in addition to /usr/lib
LDFLAGS
= -L/usr/local/lib -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib -lcudart -lcublas -lcurand -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lm -lopencv_core -lopencv_highgui -lopencv_imgproc -lboost_thread -lstdc++ -lcblas -latlas -L/path/to/nv-caffe/build/lib/ -lcaffe-nv -lproto

#cpp source file
SRC
= Detection_v1.2.cpp

OBJS
= $(SRC:.c=.o)
EXE
= Detection

all
:  $(SRC) $(EXE)


clean
:
    rm
-f *.o
    rm
-f $(EXE)
    find
./ -name \*.o  -delete

$
(EXE): $(OBJS)
    $
(CXX) $(OBJS) $(INCLUDE) $(LDFLAGS) -o $@

.cpp.o:
    $
(CXX) $(CFLAGS) $< -o $@



Now when I compile a very simple code like this one bellow, I get a segmentation file when running it

#include <caffe/caffe.hpp>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <algorithm>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>

using namespace caffe;
using std::string;

int main(int argc, char** argv) {
 
::google::InitGoogleLogging(argv[0]);

 
string model_file   = argv[1];
 
string trained_file = argv[2];
 
string mean_file    = argv[3];
 
//string label_file   = argv[4];
 
 
//shared_ptr<Net<float> > net_;
 
 
 
// Set Caffe mode
 
#ifdef CPU_ONLY
   
Caffe::set_mode(Caffe::CPU);
 
#else
   
Caffe::set_mode(Caffe::GPU);
 
#endif
}


what do you think could be the problem? I have used a similar makefile to compile a classification example and it works just fine (there I use the standard caffe instead of nv-caffe and everything else is the same) I can't use detectnet with standard caffe because it doesn't recognize it's python layers. I appreciate any help. thanks in advance!


sz Mousavi

unread,
Oct 2, 2016, 10:05:14 AM10/2/16
to DIGITS Users
I figured that there must be sth wrong with my makefile (though it works for standard Caffe) because I copied my code to tools directory in nv-caffe root and then ran cmake.. and make (the same steps needed for building caffe) there it produced an exe for me which works without problem. but I wonder how can I compile my code outside of caffe? what are the things missing from my makefile?

shervin.r...@gmail.com

unread,
Jan 19, 2017, 8:22:37 AM1/19/17
to DIGITS Users
Hi, could you please kindly provide the python code which you used to perform inference using detectnet?

sz Mousavi

unread,
Jan 20, 2017, 1:24:08 AM1/20/17
to shervin.r...@gmail.com, DIGITS Users
This is the code I used (which is the same code provided in DIGITS-master/examples/classification with some little tweaks to get detectnet output)

--
You received this message because you are subscribed to a topic in the Google Groups "DIGITS Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/digits-users/dvuhJA2NAac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to digits-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/digits-users/03c61f54-3925-408f-8b8b-85cc8ed7f9c0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Detect.py

shervin.r...@gmail.com

unread,
Jan 20, 2017, 4:53:48 PM1/20/17
to DIGITS Users, shervin.r...@gmail.com
many thanks.
Did you figure out how to perform the same inference task in C++?
To unsubscribe from this group and all its topics, send an email to digits-users...@googlegroups.com.

sz Mousavi

unread,
Jan 21, 2017, 2:29:31 AM1/21/17
to shervin.r...@gmail.com, DIGITS Users
Yes, I've written a code for that, which unfortunately I can't share (at least not all of it). The base code is that of cpp_classification example caffe provides.

To unsubscribe from this group and all its topics, send an email to digits-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/digits-users/6dcce0d6-abe9-47f6-ba72-b870cf882ffc%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages