[英]TypeError: __init__() got multiple values for argument 'strides'
The Nvidia model is showing error for strides, even if I initialize them to the default value of (1,1) I am using 'strides' as a replacement for the 'subsample' argument in previous versions of keras can someone explain the new syntax of using them. Nvidia 模型显示 strides 错误,即使我将它们初始化为 (1,1) 的默认值我使用 'strides' 作为先前版本 keras 中的 'subsample' 参数的替代有人可以解释新语法使用它们。
def nvidia_model():
model = Sequential()
model.add(Conv2D(24,5,5, strides = (2,2), input_shape= (66,200,3), activation='relu'))
model.add(Conv2D(36,5,5, strides = (2,2), activation = 'relu'))
model.add(Conv2D(48,5,5, strides = (2,2), activation = 'relu'))
model.add(Conv2D(64,3,3, activation = 'relu'))
model.add(Conv2D(64,3,3, activation = 'relu'))
model.add(Dropout(0.5)) #50% nodes turned to zero
model.add( Flatten())
model.add(Dense(100, activation ='relu'))
model.add(Dropout(0.5))
model.add(Dense(50, activation ='relu'))
model.add(Dense(10, activation ='relu'))
model.add(Dense(1))
optimizer = Adam(lr = 1e-3)
model.compile(loss = 'mse' , optimizer = optimizer)
return model
model = nvidia_model()
print(model.summary)
Error:
TypeError Traceback (most recent call last)
<ipython-input-83-aff2a2709b79> in <module>()
----> 1 model = nvidia_model()
2 print(model.summary)
<ipython-input-82-7942ade664af> in nvidia_model()
1 def nvidia_model():
2 model = Sequential()
----> 3 model.add(Conv2D(24,5,5, strides = (2,2), input_shape= (66,200,3), activation='relu'))
4 model.add(Conv2D(36,5,5, strides = (2,2), activation = 'relu'))
5 model.add(Conv2D(48,5,5, strides = (2,2), activation = 'relu'))
TypeError: __init__() got multiple values for argument 'strides'
I never worked with tensorflow
, but according to the documentation of Conv2D
it's defined as我从未使用过
tensorflow
,但根据Conv2D
的文档,它被定义为
tf.keras.layers.Conv2D(
filters, kernel_size, strides=(1, 1), padding='valid', data_format=None,
dilation_rate=(1, 1), groups=1, activation=None, use_bias=True,
kernel_initializer='glorot_uniform', bias_initializer='zeros',
kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None,
kernel_constraint=None, bias_constraint=None, **kwargs
)
As you can see strides
is the third parameter.如您所见,
strides
是第三个参数。
Now you use Conv2D(24,5,5, strides = (2,2), input_shape= (66,200,3), activation='relu')
where the third parameter is 5
and then you try to set strides
again with the keyword parameter.现在您使用
Conv2D(24,5,5, strides = (2,2), input_shape= (66,200,3), activation='relu')
,其中第三个参数为5
,然后您尝试再次使用关键字设置strides
范围。 It seems there is one parameter too much in your call.您的通话中似乎有一个参数过多。
Imagine the little Python gnome handling your code: "OK, the boss wants an instance of Conv2D
. He sets the first argument filters
to 4
, the second argument kernel_size
to 2
and the third argument strides
to 2
. Done with the positional arguments. Now let's continue with the keyword arguments. Here we have strides
and ... oh, I already have strides
, so I don't know what to do. The boss might be angry so I'll tell him exactly what happenend: TypeError: __init__() got multiple values for argument 'strides'
"想象一下处理你的代码的小 Python gnome:“好吧,老板想要一个
Conv2D
的实例。他将第一个参数filters
为4
,第二个参数kernel_size
为2
,第三个参数strides
为2
。完成位置参数。现在让我们继续关键字参数。这里我们有strides
和...哦,我已经有了strides
,所以我不知道该怎么办。老板可能生气了,所以我会告诉他到底发生了什么: TypeError: __init__() got multiple values for argument 'strides'
“
model.add(Conv2D(24,5,5, strides = (2,2), input_shape= (66,200,3), activation='relu'))
model.add(Conv2D(36,5,5, strides = (2,2), activation = 'relu'))
model.add(Conv2D(48,5,5, strides = (2,2), activation = 'relu'))
For these lines use parentheses like the following example对于这些行,请使用括号,如下例所示
model.add(Conv2D(24,(5,5), strides = (2,2), input_shape= (66,200,3), activation='relu'))
model.add(Conv2D(36,(5,5), strides = (2,2), activation = 'relu'))
model.add(Conv2D(48,(5,5), strides = (2,2), activation = 'relu'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.