New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in python interface. " Net.__init__(Net, str, str, int) did not match C++ signature" #3220

Closed
suruoxi opened this Issue Oct 20, 2015 · 15 comments

Comments

Projects
None yet
@suruoxi
Copy link

suruoxi commented Oct 20, 2015

I tried to init a net with the python code:

net = caffe.Net('models/bvlc_reference_caffenet/deploy.prototxt',
                              'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel',
                              caffe.TEST)

The following error is reported:

Boost.Python.ArgumentError: Python argument types in
Net.__init__(Net, str, str, int)
did not match C++ signature:
 __init__(boost::python::api::object, std::string, std::string, int)
__init__(boost::python::api::object, std::string, int)

I think the python interface is compatible with C++ signature. Then why is this error reported?

OpenSuse 13.02 64bit

@suruoxi

This comment has been minimized.

Copy link
Author

suruoxi commented Oct 21, 2015

Well, I solved this problem.
The reason is python str can not convert to c++ std::string .
I change the following lines in $CAFFE_ROOT/python/caffe/_caffe.cpp

shared_ptr<Net<Dtype> > Net_Init( string param_file, int phase) ...
shared_ptr<Net<Dtype> > Net_Init( string param_file, string pretrained_param_file, int phase) ...    

to

shared_ptr<Net<Dtype> > Net_Init( char * param_file, int phase) ...
shared_ptr<Net<Dtype> > Net_Init( char * param_file, char * pretrained_param_file, int phase) ...    

And it's normal now.

@suruoxi suruoxi changed the title Error in python interface. Error in python interface. " Net.__init__(Net, str, str, int) did not match C++ signature" Oct 21, 2015

@suruoxi suruoxi closed this Oct 21, 2015

@ry

This comment has been minimized.

Copy link

ry commented Jan 21, 2016

I hit this same error in Jan 2016. @suruoxi's fix seems to work.

diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp
index 4ea2ec6..4c558cb 100644
--- a/python/caffe/_caffe.cpp
+++ b/python/caffe/_caffe.cpp
@@ -75,7 +75,7 @@ void CheckContiguousArray(PyArrayObject* arr, string name,

 // Net constructor for passing phase as int
 shared_ptr<Net<Dtype> > Net_Init(
-    string param_file, int phase) {
+    char* param_file, int phase) {
   CheckFile(param_file);

   shared_ptr<Net<Dtype> > net(new Net<Dtype>(param_file,
@@ -85,7 +85,7 @@ shared_ptr<Net<Dtype> > Net_Init(

 // Net construct-and-load convenience constructor
 shared_ptr<Net<Dtype> > Net_Init_Load(
-    string param_file, string pretrained_param_file, int phase) {
+    char* param_file, char* pretrained_param_file, int phase) {
   CheckFile(param_file);
   CheckFile(pretrained_param_file);

Maybe has something to do with differing versions of Boost? Please reopen this issue

@codegeniur

This comment has been minimized.

Copy link

codegeniur commented Mar 26, 2016

Hi, I've the same error too and did the above but it didn't work.
How to make this work?

ArgumentError Traceback (most recent call last)
in ()
10 model="numbers_deploy.prototxt"
11 weights="numbers_iter_5000.caffemodel"
---> 12 net = caffe.Net(model,weights)
13 net.set_phase_test()
14 net.set_raw_scale('data', 255.0)

ArgumentError: Python argument types in
Net.init(Net, str, str)
did not match C++ signature:
init(boost::python::api::object, std::1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, int)
__init
(boost::python::api::object, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, int)`

@Mithul

This comment has been minimized.

Copy link

Mithul commented Apr 30, 2016

Running Ubuntu 15.10 and receive the same error on the ipython example 00

net = caffe.Net(model_def,      # defines the structure of the model
                model_weights,  # contains the trained weights
                caffe.TEST)     # use test mode (e.g., don't perform dropout)
Boost.Python.ArgumentError: Python argument types in
Net.__init__(Net, str, str, int)
did not match C++ signature:
 __init__(boost::python::api::object, std::string, std::string, int)
__init__(boost::python::api::object, std::string, int)

the above fix does not work for me

@lukeyeager

This comment has been minimized.

Copy link
Contributor

lukeyeager commented May 2, 2016

If you take a careful look at the error message, the constructor is expecting strings for the first two arguments. What are the types of model_def and model_weights? They should be filenames.

@kscottz

This comment has been minimized.

Copy link

kscottz commented Jun 27, 2016

I ran into this issue recent. I found that just wrapping the input args with str() seemed to get the function signature to match. I.e.

net = caffe.Net(str(model_def),      # defines the structure of the model
                str(model_weights),  # contains the trained weights
                caffe.TEST)     # use test mode (e.g., don't perform dropout)

@ajtulloch

This comment has been minimized.

Copy link
Contributor

ajtulloch commented Jun 29, 2016

You may be using Python 3/from future import unicode_literals, in which case wrapping with str() works.

@groakat

This comment has been minimized.

Copy link

groakat commented Aug 19, 2016

I had this problem, because I had boost installed in anaconda when compiling caffe. Compiling caffe without boost solves this problem.

@kravchyuriy

This comment has been minimized.

Copy link

kravchyuriy commented Jan 4, 2017

Reinstalling latest version of Boost from sources resolved that problem for me (Ubuntu 16).

@isn4

This comment has been minimized.

Copy link

isn4 commented Apr 2, 2017

Since this seems to be a boost error, what version of boost is everyone running?

@DaliaMarzouk

This comment has been minimized.

Copy link

DaliaMarzouk commented May 27, 2017

Any one could solve this problem. I am facing the same error and tried many solutions without a luck

@atakemura

This comment has been minimized.

Copy link

atakemura commented Jun 14, 2017

Encountered this error today, solved by installing the latest boost from source.

Ubuntu 16.04, anaconda3, Python 3.6, CUDA 8, Boost 1.64

  1. Removed boost from conda (i.e. conda uninstall boost)
  2. Tell b2 to use the stuff that came with conda when building Boost
    $ ./b2 install -j8 cxxflags="-std=c++11 -I<your conda dir>/include/python3.6m"
  3. Make sure conda lib/include are included in Makefile.config
  4. $ make all -j8

Additionally, to get $ make runtest to pass,

  1. Add export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<your local boost root>/boost_1_64_0/lib:<your conda loot>/lib to your .bashrc and refresh

I encountered this error in examples/00-classification.ipynb, where it tried to load trained net/weight with caffe.Net(...).
Initially I had even weirder errors because the default boost on this Ubuntu is 1.58 and conda boost was 1.61, and there was no compatible boost on conda repo for py36, so if it's using 1.61 to build it will later complain it can't find 1.61 in ldconfig and vice versa.

@aniket03

This comment has been minimized.

Copy link

aniket03 commented Jun 22, 2017

@suruoxi I also faced the same issue and tried the solution you have stated but it didn't work out for me. Do we also need to compile _caffe.cpp again here. I can see a file _caffe.so thought it might be related.

^ Sorted just had to run make pycaffe for it to be compiled again. Thanks for the solution though

@flyinskyin2013

This comment has been minimized.

Copy link

flyinskyin2013 commented May 25, 2018

I use above way to slove my same problem.
When I create Net, the weight-model path must be string-type. So,If you can not ensure the parameter's type,Please do use str() to convert it to string-type

@kr11

This comment has been minimized.

Copy link

kr11 commented Sep 20, 2018

as @suruoxi said, in the newest version of _caffe.cpp, I replace all parameters with the type of string in Net_Init-like functions with char *. After changing, don't forget re-run make pycaffe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment