conv2d() got an unexpected keyword argument 'border_mode'

11,423

Solution 1

Well, there isn't a border_mode in keras.

There is padding='valid' or padding='same'.

Always check the documentation to use the layers and functions properly.

Solution 2

Just as a side note in case anyone still has this issue, this is an issue of backward compatibility with Keras1.x. "border_mode" used to exist as an argument to the Convolution2D class in (at least) Keras1.1.0 and as such is still hanging around in a lot of older code.

In Keras2 series (I referenced 2.3.1) you will see that almost the entire API to Convolution2D has changed, so if you are porting a repository using an older version of Keras I doubt border_mode would be the biggest of your concerns.

Share:
11,423

Related videos on Youtube

mageshwaran
Author by

mageshwaran

Updated on June 04, 2022

Comments

  • mageshwaran
    mageshwaran almost 2 years

    when i try to run this code with keras-2.1.3 and theano-1.0.1 https://github.com/marcellacornia/sam/blob/master/attentive_convlstm.py

    def get_initial_states(self, x):
        initial_state = K.sum(x, axis=1)
        initial_state = K.conv2d(initial_state, K.zeros((self.nb_filters_out, self.nb_filters_in, 1, 1)), border_mode='same')
        initial_states = [initial_state for _ in range(len(self.states))]
    
        return initial_states
    
    Traceback (most recent call last):
      File "main.py", line 63, in <module>
        m = Model(input=[x, x_maps], output=sam_resnet([x, x_maps]))
      File "E:\sam-master\models.py", line 136, in sam_resnet
        nb_cols=3, nb_rows=3)(att_convlstm)
      File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 617, in __call__
        output = self.call(inputs, **kwargs)
      File "E:\sam-master\attentive_convlstm.py", line 143, in call
        initial_states = self.get_initial_states(x)
      File "E:\sam-master\attentive_convlstm.py", line 42, in get_initial_states
        initial_state = K.conv2d(initial_state, K.zeros((self.nb_filters_out, self.nb_filters_in, 1, 1)), border_mode='same')
    TypeError: conv2d() got an unexpected keyword argument 'border_mode'
    
  • Matt Messersmith
    Matt Messersmith about 6 years
    I upvoted, because answers like these are somehow still needed. 2018 and we still aren't reading the docs, tsk tsk
  • mageshwaran
    mageshwaran about 6 years
    thanks for the help, after I change this I get this error ValueError: It seems that you are using the Keras 2 and you are passing both kernel_size and strides as integer positional arguments. For safety reasons, this is disallowed. Pass strides as a keyword argument instead. i'm try to run this code with keras 2.1.3
  • Daniel Möller
    Daniel Möller about 6 years
    Are you sure the error is in the same line as before? --- You should probably post another question for that error, showing in detail where the error appears. (If you consider that my answer solved your initial problem, please mark it as answered).
  • Daniel Möller
    Daniel Möller about 6 years
    If the problem is indeed in the same line, try: K.conv2d(x=initial_state,kernel= np.zeros((self.nb_filters_out, self.nb_filters_in, 1, 1)), padding='same')
  • Daniel Möller
    Daniel Möller about 6 years
    Notice that the expected shape for the filter is actually (sizeX, sizeY, inputChannels, outputChannels).