Search code examples
pythonkeras-layermax-pooling

MaxPooling2D has incorrect syntax which i can't find


i'm trying to make a simple classification model for the cifar-10 dataset. The model fails when it gets to Maxpooling fuction. It says that it has the incorrect Syntax but for the life of me i cannot figure out whats wrong.

Is it the version of keras i'm using? when i add maxpooling to the model with a size of 2, 2 it don't work and in the documentation, i am doing the exact same thing which makes me think its a version problem.

Sorry if the problem is obvious

 model = Sequential()
 model.add(Conv2D(32, (3,3), padding = 'same', input_shape=(32,32,3)))

 model.add(Activation('relu')

 model.add(MaxPooling2D(pool_size=(2, 2)))

 model.add(Dropout(0.25))

model.add(Flatten())

model.add(Dense(512))

model.add(Activation('relu')

model.add(Dropout(0.5))

model.add(Dense(10))

model.add(Activation('softmax'))

model.summary()

Solution

  • Max pooling does not have any issue.your issue is you are missing some brackets in the previous line. find below the corrected code

    model = Sequential()
    model.add(Conv2D(32, (3,3), padding = 'same', input_shape=(32,32,3)))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    model.add(Flatten())
    
    model.add(Dense(512))
    
    model.add(Activation('relu'))
    
    model.add(Dropout(0.5))
    
    model.add(Dense(10))
    
    model.add(Activation('softmax'))
    
    model.summary()
    

    Hope this helps.