Skip to content
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 " ArgumentError: Python argument types in Net.__init__(Net, str, str)" #6097

Closed
gromzhu opened this issue Dec 8, 2017 · 2 comments

Comments

@gromzhu
Copy link

gromzhu commented Dec 8, 2017

hi,all

I tried to init a net with the python code:
net = caffe.Net(modelDef,modelWeights)
The following error is reported:
ArgumentError: Python argument types in Net.__init__(Net, str, str) did not match C++ signature: __init__(class boost::python::api::object, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >, int) __init__(class boost::python::api::object, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > network_file, int phase, int level=0, class boost::python::api::object stages=None, class boost::python::api::object weights=None)

my system configuration

Operating system: win7
Compiler: vs2015
Python version : 2.7
caffe is cpu-only

@Noiredd
Copy link
Member

Noiredd commented Dec 8, 2017

A call to caffe.Net takes 2 or 3 arguments: a network file (prototxt) which is required, optionally initial weights (caffemodel) and phase, which is also required. Currently there are 2 allowed phases: caffe.TRAIN and caffe.TEST - you have to pass one of those to the constructor. Check the examples folder, eg. the first one in classification, to see how it's done.

Also please do not post usage, installation, or modeling questions, or other requests for help to Issues. Use the caffe-users list instead. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe. Please read the guidelines for contributing before submitting an issue or a pull request.

@Noiredd Noiredd closed this as completed Dec 8, 2017
@yezhengli-Mr9
Copy link

yezhengli-Mr9 commented Jan 7, 2021

hi,all

I tried to init a net with the python code:
net = caffe.Net(modelDef,modelWeights)
The following error is reported:
ArgumentError: Python argument types in Net.__init__(Net, str, str) did not match C++ signature: __init__(class boost::python::api::object, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >, int) __init__(class boost::python::api::object, class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > network_file, int phase, int level=0, class boost::python::api::object stages=None, class boost::python::api::object weights=None)

my system configuration

Operating system: win7
Compiler: vs2015
Python version : 2.7
caffe is cpu-only

Hi @gromzhu, have you resolved it just by caffe.TEST/caffe.TRAIN? I think I put caffe.TEST but I have problem with lxmert issue#89

Called with args:
Namespace(caffemodel='./resnet101_faster_rcnn_final_iter_320000.caffemodel', cfg_file='/opt/butd/experiments/cfgs/faster_rcnn_end2end_resnet.yml', imgroot='/workspace/images/', outfile='test_obj36.tsv', prototxt='/opt/butd/models/vg/ResNet-101/faster_rcnn_end2end_final/test.prototxt', set_cfgs=None, split='test')
/opt/butd//tools/../lib/fast_rcnn/config.py:288: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  yaml_cfg = edict(yaml.load(f))
Using config:
{'DATA_DIR': '/opt/butd/data',
 'DEDUP_BOXES': 0.0625,
 'EPS': 1e-14,
 'EXP_DIR': 'faster_rcnn_resnet',
 'GPU_ID': 0,
 'MATLAB': 'matlab',
 'MODELS_DIR': '/opt/butd/models/pascal_voc',
 'PIXEL_MEANS': array([[[102.9801, 115.9465, 122.7717]]]),
 'RNG_SEED': 3,
 'ROOT_DIR': '/opt/butd',
 'TEST': {'AGNOSTIC': False,
          'BBOX_REG': True,
          'HAS_ATTRIBUTES': True,
          'HAS_RELATIONS': False,
          'HAS_RPN': True,
          'MAX_SIZE': 1000,
          'NMS': 0.3,
          'PROPOSAL_METHOD': 'selective_search',
          'RPN_MIN_SIZE': 16,
          'RPN_NMS_THRESH': 0.7,
          'RPN_POST_NMS_TOP_N': 300,
          'RPN_PRE_NMS_TOP_N': 6000,
          'SCALES': [600],
          'SOFT_NMS': 0,
          'SVM': False},
 'TRAIN': {'AGNOSTIC': False,
           'ASPECT_GROUPING': True,
           'BATCH_SIZE': 64,
           'BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
           'BBOX_NORMALIZE_MEANS': [0.0, 0.0, 0.0, 0.0],
           'BBOX_NORMALIZE_STDS': [0.1, 0.1, 0.2, 0.2],
           'BBOX_NORMALIZE_TARGETS': True,
           'BBOX_NORMALIZE_TARGETS_PRECOMPUTED': True,
           'BBOX_REG': True,
           'BBOX_THRESH': 0.5,
           'BG_THRESH_HI': 0.5,
           'BG_THRESH_LO': 0.0,
           'FG_FRACTION': 0.5,
           'FG_THRESH': 0.5,
           'HAS_ATTRIBUTES': True,
           'HAS_RELATIONS': False,
           'HAS_RPN': True,
           'IMS_PER_BATCH': 1,
           'MAX_SIZE': 1000,
           'MIN_RELATION_FRACTION': 0.25,
           'PROPOSAL_METHOD': 'gt',
           'RPN_BATCHSIZE': 64,
           'RPN_BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
           'RPN_CLOBBER_POSITIVES': False,
           'RPN_FG_FRACTION': 0.5,
           'RPN_MIN_SIZE': 16,
           'RPN_NEGATIVE_OVERLAP': 0.3,
           'RPN_NMS_THRESH': 0.7,
           'RPN_NORMALIZE_MEANS': [0.0, 0.0, 0.0, 0.0],
           'RPN_NORMALIZE_STDS': [0.1, 0.1, 0.2, 0.2],
           'RPN_NORMALIZE_TARGETS': False,
           'RPN_POSITIVE_OVERLAP': 0.7,
           'RPN_POSITIVE_WEIGHT': -1.0,
           'RPN_POST_NMS_TOP_N': 2000,
           'RPN_PRE_NMS_TOP_N': 12000,
           'SCALES': [600],
           'SNAPSHOT_INFIX': '',
           'SNAPSHOT_ITERS': 10000,
           'USE_FLIPPED': True,
           'USE_PREFETCH': False},
 'USE_GPU_NMS': False}
missing 9/9
START caffe.set_mode_cpu()
Traceback (most recent call last):
  File "extract_nlvr2_image.py", line 203, in <module>
    generate_tsv(args.prototxt, args.caffemodel, image_ids, args.outfile)
  File "extract_nlvr2_image.py", line 90, in generate_tsv
    net = caffe.Net(prototxt, caffe.TEST, weights=weights)
Boost.Python.ArgumentError: Python argument types in
    Net.__init__(Net, str, int)
did not match C++ signature:
    __init__(boost::python::api::object, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)
    __init__(boost::python::api::object, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)
root@2c3a1f2f867c:/workspace/features#

and after I made adjustment according to #3220

// Net constructor for passing phase as int
shared_ptr<Net<Dtype> > Net_Init(
-- //    string param_file, int phase) {
++ // https://github.com/BVLC/caffe/issues/3220
++ char *param_file, int phase) {
  CheckFile(param_file);

  shared_ptr<Net<Dtype> > net(new Net<Dtype>(param_file,
      static_cast<Phase>(phase)));
  return net;
}

// Net construct-and-load convenience constructor
shared_ptr<Net<Dtype> > Net_Init_Load(
--//    string param_file, string pretrained_param_file, int phase) {
++// https://github.com/BVLC/caffe/issues/3220
++char * param_file, char * pretrained_param_file, int phase) {
  CheckFile(param_file);
  CheckFile(pretrained_param_file);

I still obtain the following:

Called with args:
Namespace(caffemodel='./resnet101_faster_rcnn_final_iter_320000.caffemodel', cfg_file='/opt/butd/experiments/cfgs/faster_rcnn_end2end_resnet.yml', imgroot='/workspace/images/', outfile='test_obj36.tsv', prototxt='/opt/butd/models/vg/ResNet-101/faster_rcnn_end2end_final/test.prototxt', set_cfgs=None, split='test')
/opt/butd//tools/../lib/fast_rcnn/config.py:288: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  yaml_cfg = edict(yaml.load(f))
Using config:
{'DATA_DIR': '/opt/butd/data',
 'DEDUP_BOXES': 0.0625,
 'EPS': 1e-14,
 'EXP_DIR': 'faster_rcnn_resnet',
 'GPU_ID': 0,
 'MATLAB': 'matlab',
 'MODELS_DIR': '/opt/butd/models/pascal_voc',
 'PIXEL_MEANS': array([[[102.9801, 115.9465, 122.7717]]]),
 'RNG_SEED': 3,
 'ROOT_DIR': '/opt/butd',
 'TEST': {'AGNOSTIC': False,
          'BBOX_REG': True,
          'HAS_ATTRIBUTES': True,
          'HAS_RELATIONS': False,
          'HAS_RPN': True,
          'MAX_SIZE': 1000,
          'NMS': 0.3,
          'PROPOSAL_METHOD': 'selective_search',
          'RPN_MIN_SIZE': 16,
          'RPN_NMS_THRESH': 0.7,
          'RPN_POST_NMS_TOP_N': 300,
          'RPN_PRE_NMS_TOP_N': 6000,
          'SCALES': [600],
          'SOFT_NMS': 0,
          'SVM': False},
 'TRAIN': {'AGNOSTIC': False,
           'ASPECT_GROUPING': True,
           'BATCH_SIZE': 64,
           'BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
           'BBOX_NORMALIZE_MEANS': [0.0, 0.0, 0.0, 0.0],
           'BBOX_NORMALIZE_STDS': [0.1, 0.1, 0.2, 0.2],
           'BBOX_NORMALIZE_TARGETS': True,
           'BBOX_NORMALIZE_TARGETS_PRECOMPUTED': True,
           'BBOX_REG': True,
           'BBOX_THRESH': 0.5,
           'BG_THRESH_HI': 0.5,
           'BG_THRESH_LO': 0.0,
           'FG_FRACTION': 0.5,
           'FG_THRESH': 0.5,
           'HAS_ATTRIBUTES': True,
           'HAS_RELATIONS': False,
           'HAS_RPN': True,
           'IMS_PER_BATCH': 1,
           'MAX_SIZE': 1000,
           'MIN_RELATION_FRACTION': 0.25,
           'PROPOSAL_METHOD': 'gt',
           'RPN_BATCHSIZE': 64,
           'RPN_BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
           'RPN_CLOBBER_POSITIVES': False,
           'RPN_FG_FRACTION': 0.5,
           'RPN_MIN_SIZE': 16,
           'RPN_NEGATIVE_OVERLAP': 0.3,
           'RPN_NMS_THRESH': 0.7,
           'RPN_NORMALIZE_MEANS': [0.0, 0.0, 0.0, 0.0],
           'RPN_NORMALIZE_STDS': [0.1, 0.1, 0.2, 0.2],
           'RPN_NORMALIZE_TARGETS': False,
           'RPN_POSITIVE_OVERLAP': 0.7,
           'RPN_POSITIVE_WEIGHT': -1.0,
           'RPN_POST_NMS_TOP_N': 2000,
           'RPN_PRE_NMS_TOP_N': 12000,
           'SCALES': [600],
           'SNAPSHOT_INFIX': '',
           'SNAPSHOT_ITERS': 10000,
           'USE_FLIPPED': True,
           'USE_PREFETCH': False},
 'USE_GPU_NMS': False}
missing 9/9
START caffe.set_mode_cpu()
Traceback (most recent call last):
  File "extract_nlvr2_image.py", line 203, in <module>
    generate_tsv(args.prototxt, args.caffemodel, image_ids, args.outfile)
  File "extract_nlvr2_image.py", line 90, in generate_tsv
    net = caffe.Net(prototxt, caffe.TEST, weights=weights)
Boost.Python.ArgumentError: Python argument types in
    Net.__init__(Net, str, int)
did not match C++ signature:
    __init__(boost::python::api::object, char*, char*, int)
    __init__(boost::python::api::object, char*, int)
root@2c3a1f2f867c:/workspace/features#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants