我是Python和深度学习的新手,并且在我的curdrent Udacity项目中遇到了这种语法错误。有133个分类,所以我把它作为输出。无论如何,请参考下面的代码,让我知道为什么我可能会收到此错误:
File "<ipython-input-1-2979a000d526>", line 18
model.add(Dense(133))
^
SyntaxError: invalid syntax
以下是代码:
from keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D
from keras.layers import Dropout, Flatten, Dense
from keras.models import Sequential
model = Sequential()
model.add(Conv2D(filters=16, kernel_size=2, strides=(2,2), padding='valid', activation='relu',
input_shape=(224, 224, 3)))# putput of (224,224,16)
model.add(MaxPooling2D(pool_size=2))#output of (112,112,16)
model.add(Conv2D(filters=32, kernel_size=2, strides=(2,2), padding='valid', activation='relu'))
#output is (112,112,32)
model.add(MaxPooling2D(pool_size=2))#output is (56,56,32)
model.add(Conv2D(filters=64, kernel_size=2, strides=(2,2), padding='same', activation='relu'))
#output is (56,56,64)
model.add(MaxPooling2D(pool_size=2))#output is (28,28,64)
#add global average pooling 2D layer
model.add(GlobalAveragePooling2D(data_format = channels_last)
# don't need to flatten after GAP model.add(Flatten())
model.add(Dense(133)) #error is here
model.add(Activation('softmax'))
### TODO: Define your architecture.
model.summary()
答案 0 :(得分:1)
你的行
model.add(GlobalAveragePooling2D(data_format = channels_last)
最后缺少一个括号。