我想在隐藏层中添加一个辍学者。我不知道是否应该在每个隐藏层的定义之前或之后执行该句子。
有人可以帮我吗?
def keras_model2(layers_dims):
L = len(layers_dims)
model = Sequential()
model.add(Dense(layers_dims[1], input_shape=(layers_dims[0],), activation="relu"))
for l in range(2, L-1):
model.add(Dense(layers_dims[l], activation="relu", kernel_initializer="random_normal",
bias_initializer="zeros"))
model.add(Dropout(0.4))
model.add(Dense(layers_dims[L-1], activation="softmax", kernel_initializer="random_normal",
bias_initializer="zeros"))
return model