导入relu激活时出错

时间:2017-11-30 21:01:18

标签: python-3.x deep-learning keras jupyter-notebook theano

Notebook环境:Python3

if K.image_data_format() == 'channels_first':
    input_shape = (3, img_rows, img_cols)
else:
    input_shape = (img_rows, img_cols, 3)

model = Sequential()    
model.add(Conv2D(32, (3, 3), input_shape=input_shape)
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

错误:

File "<ipython-input-6-50fd40b32811>", line 21
    model.add(Activation('relu'))
        ^
SyntaxError: invalid syntax

我已经检查了用于导入relu的keras文档,它的结果非常相似。这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

您的语法正确,上面的行中缺少一个字符:

model.add(Conv2D(32, (3, 3), input_shape=input_shape))

您还可以将激活指定为Conv2D图层的一部分:

model.add(Conv2D(32, (3, 3), activation='relu', input_shape=input_shape))