gpt4 book ai didi

python - 如何添加 keras dropout 层?

转载 作者:行者123 更新时间:2023-12-05 02:46:51 24 4
gpt4 key购买 nike

如何添加 Keras 丢弃层?不幸的是,我不知道我必须在哪里添加这一层。我查看了 2 个链接:

比如我见过这个

model.add(Dense(60, input_dim=60, activation='relu', kernel_constraint=maxnorm(3)))
model.add(Dropout(0.2))
model.add(Dense(30, activation='relu', kernel_constraint=maxnorm(3)))
model.add(Dropout(0.2))
model.add(Dense(1, activation='sigmoid'))

据我所知,密集层是用循环创建的,所以我不确定如何添加它。

def get_Model(...):

# build dense layer for model
for i in range(1, len(dense_layers)):

layer = Dense(dense_layers[i],
activity_regularizer=l2(reg_layers[i]),
activation='relu',
name='layer%d' % i)
mlp_vector = layer(mlp_vector)

predict_layer = Concatenate()([mf_cat_latent, mlp_vector])
result = Dense(1, activation='sigmoid',
kernel_initializer='lecun_uniform', name='result')

model = Model(inputs=[input_user, input_item], outputs=result(predict_layer))

return model

最佳答案

试试这个:

for i in range(1, len(dense_layers)):

layer = Dense(dense_layers[i],
activity_regularizer=l2(reg_layers[i]),
activation='relu',
name='layer%d' % i)
mlp_vector = layer(mlp_vector)
mlp_vector = Dropout(0.2)(mlp_vector)

在这里查看函数式 API https://keras.io/guides/functional_api/

关于python - 如何添加 keras dropout 层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65327655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com