尝试通过以下代码构建图层,但出现错误
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
X = pickle.load(open("X.pickle","rb"))
y = pickle.load(open("y.pickle","rb"))
X = X/255.0
model = Sequential()
model.add(Conv2D(64,(3,3) , input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add((Conv2D(64, (3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss="binary_crossentropy",
optimizer="adam",
metrics=['accuracy'])
model.fit(X, y, batch_size=1, validation_split=0.1)
请有人帮忙。我在python 2.7环境中使用jupyter notebook,上面的代码返回:
File "<ipython-input-37-f4c444b06108>", line 16
model.add(Activation("relu"))
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
此错误通常表示报告的行 上方 没有正确结束。请注意,第15行上有一个多余的括号;;)
model.add((Conv2D(64, (3,3))) # <--- 4 open, 3 closed
model.add(Activation("relu"))