qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.76k stars 1.03k forks source link

dropout layer in Unet #463

Open nouha-mejri opened 3 years ago

nouha-mejri commented 3 years ago

I'm using unet for semantic segmentation but my model is overfitting, so can I add a dropout layer for unet because I think that there isn't .

luna9722 commented 3 years ago

Hello, Yes there isn't dropout layers in the implementation of unet, but you can use regularizers set_regularization(model, kernel_regularizer=keras.regularizers.l2(0.001),bias_regularizer=keras.regularizers.l2(0.001)) you can also try data augmentation. But if it is necessary to add dropout you can stop after some layers and add after it the dropout layers you want like this: model = sm.Unet(......) model_input = model.input model_output = model.get_layer('final_conv').output (any layer you want)

add dropout

model_output = keras.layers.Dropout(0.3)(model_output)

add activation

output = keras.layers.Activation(activation, name=activation)(model_output) model_dp = keras.models.Model(model_input, output)