问题描述
我试图在Keras中构建顺序模型,但是当我编译模型时,出现此错误,该如何解决?
# Step 3: Model Creation
model = Sequential()
model.add(Conv2D(32,(3,3),Input_shape(32,32,padding = "same",activation = 'relu',kernel_constraint = maxnorm(3)))
model.add(Dropout(0.2))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(512,kernel_constraint=maxnorm(3)))
model.add(Dropout(0.5))
model.add(Dense(num_classes,activation='relu'))
#Configure the optimizer
sgd = SGD(lr = 0.01,momentum =0.9,decay = (0.01/25),nesterov = False)
#compile the model
model.compile(loss = 'categorical_crossentropy',optimizer = sgd,metrics = ['accuracy'])
这是我得到的错误:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-32-c2c434db6c57> in <module>()
1 # Step 3: Model Creation
2 model = Sequential()
----> 3 model.add(Conv2D(32,4 kernel_constraint = maxnorm(3)))
5 model.add(Dropout(0.2))
NameError: name 'Input_shape' is not defined
解决方法
您在model.add()参数的第3行中缺少 = 符号:Input_shape = (32,32,3)