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

The 1st entry of padding argument must be a tuple of 2 integers. Received: 3 #2

Closed
gohar94 opened this issue Jul 25, 2017 · 6 comments

Comments

@gohar94
Copy link

gohar94 commented Jul 25, 2017

ubuntu@ip-10-0-0-5:~/keras/keras/caffe$ python caffe2keras.py -load_path 'models/' -prototxt 'deploy_new.prototxt' -caffemodel 'go.caffemodel'
Using Theano backend.
Converting model...
CREATING MODEL
Traceback (most recent call last):
  File "caffe2keras.py", line 46, in <module>
    main(args)
  File "caffe2keras.py", line 34, in main
    model = convert.caffe_to_keras(args.load_path+'/'+args.prototxt, args.load_path+'/'+args.caffemodel, debug=args.debug)
  File "/home/ubuntu/keras/keras/caffe/convert.py", line 53, in caffe_to_keras
    debug)
  File "/home/ubuntu/keras/keras/caffe/convert.py", line 197, in create_model
    input_layers = ZeroPadding2D(padding=(pad_h, pad_w), name=name + '_zeropadding')(input_layers)
  File "/home/ubuntu/keras/keras/legacy/interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/home/ubuntu/keras/keras/layers/convolutional.py", line 1641, in __init__
    '1st entry of padding')
  File "/home/ubuntu/keras/keras/utils/conv_utils.py", line 30, in normalize_tuple
    str(n) + ' integers. Received: ' + str(value))
ValueError: The `1st entry of padding` argument must be a tuple of 2 integers. Received: 3

I keep getting the error above - anyone know why this might be happening?

@qxcv
Copy link
Owner

qxcv commented Jul 25, 2017

That's really odd. What happens if you edit /home/ubuntu/keras/keras/utils/conv_utils.py so that normalize_tuple prints out its argument type? Something like this:

def normalize_tuple(value, n, name):
    """
    … docstring snipped…
    """
    # v should print "int" and an int-ish value, unless there's something weird going on.
    print(type(value))
    print(value)
    # ^
    if isinstance(value, int):
        return (value,) * n
    else:
        try:
            value_tuple =# rest of function unchanged

My guess is that there's a numpy integer floating around somewhere in there, and the check in at the beginning of normalize_tuple is failing to spot it.

@gohar94
Copy link
Author

gohar94 commented Jul 26, 2017

<type 'long'>
3

This is what it prints!

@gohar94
Copy link
Author

gohar94 commented Jul 26, 2017

The number of values in the tuple seems to be an issue, the type is long which seems to be acceptable. Any ideas why this might be happening? Thanks a bunch for the help.

@qxcv
Copy link
Owner

qxcv commented Jul 26, 2017

isinstance(long(3), int) should be False, which would cause the observed problem. Running it with Python 3 (which has no long) or replacing isinstance(n, int) with isinstance(n, (int, long)) (on the Keras side) will hopefully make it work.

@gohar94
Copy link
Author

gohar94 commented Jul 26, 2017

Thanks, that resolved the error. Getting this now, though:

Traceback (most recent call last):
  File "caffe2keras.py", line 46, in <module>
    main(args)
  File "caffe2keras.py", line 34, in main
    model = convert.caffe_to_keras(args.load_path+'/'+args.prototxt, args.load_path+'/'+args.caffemodel, debug=args.debug)
  File "/home/ubuntu/keras/keras/caffe/convert.py", line 53, in caffe_to_keras
    debug)
  File "/home/ubuntu/keras/keras/caffe/convert.py", line 197, in create_model
    input_layers = ZeroPadding2D(padding=(pad_h, pad_w), name=name + '_zeropadding')(input_layers)
  File "/home/ubuntu/keras/keras/engine/topology.py", line 596, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/ubuntu/keras/keras/layers/convolutional.py", line 1685, in call
    data_format=self.data_format)
  File "/home/ubuntu/keras/keras/backend/theano_backend.py", line 1124, in spatial_2d_padding
    input_shape = x.shape
AttributeError: 'list' object has no attribute 'shape'

@qxcv
Copy link
Owner

qxcv commented Jul 27, 2017

Not sure why that's happening. Are you sure you're actually using the code from this repo? My line 197 of models.py is different from the line 197 you have there, and the module name is also wrong. This code in this repo is based on the converter in @MarcBS Keras fork—based on module names, I suspect you're actually using that.

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

2 participants