[英]SyntaxError: positional argument follows keyword argument in CNN model
I am trying to make a CNN model and I get a the following error我正在尝试制作 CNN model,但出现以下错误
keras.layers.MaxPooling2D(pool_size = (2,2), padding= "same"),
^
SyntaxError: positional argument follows keyword argument
the error applies when I want to add a dropout or max pooling, I will add my code below and comment the lines that gave me the mentioned syntax error.当我想添加辍学或最大池时,该错误适用,我将在下面添加我的代码并注释给我提到的语法错误的行。
I get different errors when I try to run dropout and comment out maxpooling and vice versa.当我尝试运行 dropout 并注释掉 maxpooling 时,我会遇到不同的错误,反之亦然。
Note: I am using hp.Choice and hp.Int from kerastuner from the following documentary ( https://keras-team.github.io/keras-tuner/ ) It's working fine I am pretty sure the error isn't because of misuse of it.注意:我正在使用来自以下纪录片( https://keras-team.github.io/keras-tuner/ )的 kerastuner 的 hp.Choice 和 hp.Int 工作正常我很确定错误不是因为滥用它。
model = keras.Sequential([
keras.layers.Conv2D(
keras.layers.BatchNormalization(),
input_shape = (img_rows, img_cols, 1),
kernel_size = hp.Choice("conv1_kernel", values = [3, 6]),
filters = hp.Int("conv1_filters", min_value = 32, max_value = 128, step = 16),
#keras.layers.MaxPooling2D(pool_size = (2,2), padding= "same"),
#keras.layers.Dropout(0.2),
activation = "relu"
),
keras.layers.Conv2D(
keras.layers.BatchNormalization(),
input_shape = (img_rows, img_cols, 1),
kernel_size = hp.Choice("conv2_kernel", values = [3, 6]),
filters = hp.Int("conv2_filters", min_value = 32, max_value = 64, step = 16),
#keras.layers.MaxPooling2D(pool_size = (2,2), padding = "same"),
#keras.layers.Dropout(0.5),
activation = "relu"
),
keras.layers.Flatten(),
keras.layers.Dense(
units = hp.Int("dense1_units", min_value = 16, max_value = 256, step = 16),
activation = "relu"
),
keras.layers.Dense(units = 7, activation = "softmax")
])
model.compile(optimizer=keras.optimizers.Adam(hp.Choice('learning_rate', values=[1e-1, 1e-2, 1e-3])),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model```
keras.layers.MaxPooling2D(pool_size = (2,2), padding= "same"),
keras.layers.Dropout(0.2),
are the same entities as keras.layers.Conv2D
: they are layers and should be added in the same way to model architecture:是与
keras.layers.Conv2D
相同的实体:它们是层,应该以相同的方式添加到 model 架构:
keras.layers.Conv2D(
input_shape = (img_rows, img_cols, 1),
kernel_size = hp.Choice("conv1_kernel", values = [3, 6]),
filters = hp.Int("conv1_filters", min_value = 32, max_value = 128, step = 16),
activation = "relu"
),
keras.layers.BatchNormalization(),
keras.layers.MaxPooling2D(pool_size = (2,2), padding= "same"),
keras.layers.Dropout(0.2),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.