Classification in C++ using caffe DLL provided by the new Windows branch

1,291 views
Skip to first unread message

Marianne

unread,
Dec 8, 2016, 4:43:28 AM12/8/16
to Caffe Users
I checked out the new Windows branch led by Guillaume Dumont (https://github.com/BVLC/caffe/tree/windows) and was very happy about the option to build caffe as a DLL.
I successfully compiled it and caffe.exe as well as classification.exe work perfectly using the command line interface. However, I'm struggeling to use the DLL in my own C++ project now.

To start somewhere, I want to classify an image and tried to follow the example code given in classification.cpp.

caffe::Caffe::set_mode(caffe::Caffe::GPU);
std
::shared_ptr<caffe::Net<float>> net;
net
.reset(new caffe::Net<float>("C:\\path\\to\\modelfile", caffe::TEST));
net
->CopyTrainedLayersFrom("C:\\path\\to\\trained\\model");

When loading the model file, I get an error:

Check failed: fd != -1 (-1 vs. -1) File not found: H· 7õ

In fact, the strange file name representation in the error messages changes in each run, although the path remains the same.

Has anyone managed to classify an image in C++ using the caffe DLL and is willing to provide a code snippet? Using the python or Matlab interface is not a preferred alternative as I want to use caffe functions from an existing C++ framework.

Guillaume Dumont

unread,
Dec 9, 2016, 8:59:16 AM12/9/16
to Caffe Users
Hi Marianne,

Glad to see that the windows DLL build worked for you. I successfully did what you suggest but can't really provide an example for it.

One thing I can suggest though is trying to build the DLL in debug mode and stepping through the caffe code to see why the file opening fails.

Something else I can suggest is to call caffe::GlobalInit, I am not sure it that is required but who knows.

Other than that, if you want to setup a sample example project on github that I can try to reproduce your problem this could somehow be added to the test suite in caffe itself so that other people who want to acheive the same thing can get a working example.

Guillaume

Marianne

unread,
Dec 15, 2016, 10:04:33 AM12/15/16
to Caffe Users
Hi Guillaume,

thanks for your comments regarding my issue. I continued working on it and want to share my progress:

1) Calling caffe::GlobalInit did not change anything, seems like it is not required.

2) I've been thinking about whether this could be an encoding error. I changed the encoding of my project to unicode as in the caffe examples. No change.

3) I run the above code from console and passed the path to the model file as an argument, to better simulate the behaviour of classification.exe. Still the same error.

std::string model_file = argv[1];
std
::shared_ptr<caffe::Net<float>> net_;
net_
.reset(new caffe::Net<float>(model_file, caffe::TEST));

4) Stepping through the caffe code as you suggested is what I want to do next. Since I built caffe with Ninja instead of Visual Studio and therefore don't get any Visual Studio files, I don't quite know how to do this. Could you give me a hint?
Today I tried out the new build script, here I would end up with Visual Studio files to debug further, right? Unfortunately, I was not able to build caffe successfully this way, see https://groups.google.com/forum/#!topic/caffe-users/gEqEdN5Vc8E.

If debugging does not help, I can try to upload the project to make the error reproducable for you.

Guillaume Dumont

unread,
Dec 16, 2016, 9:29:42 AM12/16/16
to Caffe Users
Just create a dummy project in Visual Studio and in the Debugging properties change the Command property to the path of the caffe.exe

Alternatively, you can call DebugBreak(); at the beginning of main and Windows will show a window like the process crashed so you can attach to it Debug > Attach To Process.

HTH

Bene

unread,
Dec 20, 2016, 9:41:28 AM12/20/16
to Caffe Users
Hey Marianne,
were you able to do it?
Which in instruction did you use?
I think we habe both the same goal - to implement caffe to our own VS C++ Project.

I was able to build caffe on windows with VS2015 - I was also able to train my own data set and use it. Everything works fine. But now i want to implement the caffe api to my project to "use" / or to "handle" the classification results.

Is there a way to go?

Cheers,

Bene

Marianne

unread,
Jan 5, 2017, 11:12:57 AM1/5/17
to Caffe Users
Hi Bene,

I'm still stuck on the same error... Wish I could help you.

Huck Wach

unread,
Jan 5, 2017, 1:12:43 PM1/5/17
to Caffe Users
Bene and Marianne,

I am trying to do the same thing as you (I think) but it seems like you got further than I did.  I followed the directions (https://github.com/BVLC/caffe/tree/windows).  Are there special steps if you want to build the DLL?

I am trying to use Caffe in my own C++ project which resembles the cpp_classification example.  When I include caffe.hpp I encountered many errors related to not finding include files but seemed to be able to get through those by modifying my project include directories (I needed things in caffe/include/caffe , caffe/build/include/caffe/proto, caffe/build/libraries/include and  caffe\build\libraries\include\boost-1_61).  

However, now I get a ton of build errors in proto/caffe.pb.h which is included by common.hpp which is included by caffe.hpp (the one and only caffe related include I'm using in my code).  The first of the errors is on this line...

float min() const;

which gives an error "invalid type for a bit field"

Any ideas?
Message has been deleted

Bene

unread,
Jan 9, 2017, 5:14:02 AM1/9/17
to Caffe Users
Hey Huck, Hey, Marianne,

good News to you. I was able to include caffe to my "regular" VS C++ project.  (Windows 10 , 64bit, cuda 8, cuDnn, visual studio 2015).

I will post a my wokflow + my Visual Studio Setup during the next week (Sorry, at the moment i am very busy but  i really want to share my solution with you)

Cheers and dont give up!

Marianne

unread,
Jan 12, 2017, 11:13:51 AM1/12/17
to Caffe Users
Congrats! I'm very interested in your solution.

wolge...@gmail.com

unread,
Feb 6, 2017, 10:39:35 AM2/6/17
to Caffe Users
ths is Wolfgang - one more guy struggling with calls on caffe dll. Bene - how is your Project going ? Can you share some Information?

Also, does anybody know how to catch the results for a object collection (with Position) in object detection?

best regards


wuying2...@gmail.com

unread,
Aug 17, 2017, 7:08:43 AM8/17/17
to Caffe Users
Hi, Bene:
    congrats,  i'm a guy struggling with calls on caffe dll.  how is your Project going ? Can you share some Information?   Thanks.


在 2017年1月9日星期一 UTC+8下午6:14:02,Bene写道:
Reply all
Reply to author
Forward
0 new messages