导入relu激活报错
Error in importing relu activation
笔记本环境: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
我查看了keras导入relu的文档,完全一样。这里出了什么问题?
你的语法是正确的,上面一行少了一个字符:
model.add(Conv2D(32, (3, 3), input_shape=input_shape))
您还可以将激活指定为 Conv2D 层的一部分:
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=input_shape))
笔记本环境: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
我查看了keras导入relu的文档,完全一样。这里出了什么问题?
你的语法是正确的,上面一行少了一个字符:
model.add(Conv2D(32, (3, 3), input_shape=input_shape))
您还可以将激活指定为 Conv2D 层的一部分:
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=input_shape))