Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

machine learning - model.add( Dropout(0.25)) SyntaxError: invalid syntax in CNN

I am trying to do a CNN based project. But when I want to build a CNN model, I got an error in "model.add(Dropout(0.25))" in line 14. In the previous model.add(Dropout(0.25)) , i did not get error in line 9. Can anyone tell me what is the problem here? Why does it give an error?

 model = Sequential()

model.add(Conv2D(32 , kernel_size=(3,3), acitvation ='relu' , padding='same' , input_shape = (28,28,1)))
model.add(BatchNormalization())

model.add(Conv2D(32,kernel_size=(3,3),activation='relu' , padding='same'))
model.add(BatchNormalization())
model.add(MaxPool2D(pool_size=(2,2) ,strides=2))
model.add(Dropout(0.25))

model.add(Conv2D(64,kernel_size=(3,3),activation='relu' , padding='same'))
model.add(BatchNormalization())
model.add(MaxPool2D(pool_size=(2,2),strides=2,padding='valid')
model.add( Dropout(0.25))

model.add(Flatten())

model.add(Dense(512,activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.25))

model.add(Dense(1024,activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.5))             

model.add(Dense(10,activation='softmax'))

and the error message is

 File "<ipython-input-53-e1c5cf3b08b4>", line 14
    model.add( Dropout(0.25))
        ^
SyntaxError: invalid syntax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You forgot to give the bracket on the line above. Just put the bracket at the end of line 13.

 model = Sequential()
    
    model.add(Conv2D(32 , kernel_size=(3,3), acitvation ='relu' , padding='same' , input_shape = (28,28,1)))
    model.add(BatchNormalization())
    
    model.add(Conv2D(32,kernel_size=(3,3),activation='relu' , padding='same'))
    model.add(BatchNormalization())
    model.add(MaxPool2D(pool_size=(2,2) ,strides=2))
    model.add(Dropout(0.25))
    
    model.add(Conv2D(64,kernel_size=(3,3),activation='relu' , padding='same'))
    model.add(BatchNormalization())
    model.add(MaxPool2D(pool_size=(2,2),strides=2,padding='valid'))
    model.add( Dropout(0.25))
    
    model.add(Flatten())
    
    model.add(Dense(512,activation='relu'))
    model.add(BatchNormalization())
    model.add(Dropout(0.25))
    
    model.add(Dense(1024,activation='relu'))
    model.add(BatchNormalization())
    model.add(Dropout(0.5))             
    
    model.add(Dense(10,activation='softmax'))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...