TypeError: Sequential.add() got an unexpected keyword argument 'padding'

Question:

I’m trying to build a model for image classification, but when I run the code, this error shows:
TypeError: Sequential.add() got an unexpected keyword argument 'padding' this is the model:

model.add(Conv2D(32, (3,3), 1, activation='relu', input_shape=(256,256,3), padding='same', kernel_regularizer=regularizers.l2(0.01)))
model.add(MaxPooling2D())

model.add(Conv2D(64, (3,3), 1, activation='relu'), padding='same', kernel_regularizer=regularizers.l2(0.01))
model.add(MaxPooling2D())

model.add(Conv2D(32, (3,3), 1, activation='relu'), padding='same', kernel_regularizer=regularizers.l2(0.01))
model.add(MaxPooling2D())

model.add(Flatten())

model.add(Dense(256, activation='relu'), kernel_regularizer=regularizers.l2(0.01))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))

and the error appears in the 4th line, the second time I’m adding the padding

Asked By: Santiago A

||

Answers:

model.add(Conv2D(32, (3,3), 1, activation='relu', input_shape=(256,256,3), padding='same', kernel_regularizer=regularizers.l2(0.01)))

model.add(Conv2D(64, (3,3), 1, activation='relu'), padding='same', kernel_regularizer=regularizers.l2(0.01))

In the first call, because of the arrangement of parentheses, padding is an argument to Conv2D().

But in the second call your parentheses are different, so padding is incorrectly given as an argument to model.add().

The second call has a closing parentheses after activation='relu', where the first call does not.

Answered By: John Gordon
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.