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

Time:08-03

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

CodePudding user response:

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.

  • Related