Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion keras_hub/src/models/segformer/segformer_image_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class SegFormerImageSegmenter(ImageSegmenter):
projection_filters: int, number of filters in the
convolution layer projecting the concatenated features into a
segmentation map. Defaults to 256`.
dropout_rate: float. The dropout rate to apply before the
segmentation head. Defaults to `0.1`.


Example:
Expand Down Expand Up @@ -121,6 +123,7 @@ def __init__(
backbone,
num_classes,
preprocessor=None,
dropout_rate=0.1,
**kwargs,
):
if not isinstance(backbone, keras.layers.Layer) or not isinstance(
Expand All @@ -137,7 +140,7 @@ def __init__(

self.backbone = backbone
self.preprocessor = preprocessor
self.dropout = keras.layers.Dropout(0.1)
self.dropout = keras.layers.Dropout(dropout_rate)
self.output_segmentation_head = keras.layers.Conv2D(
filters=num_classes, kernel_size=1, strides=1
)
Expand All @@ -162,13 +165,15 @@ def __init__(
# === Config ===
self.num_classes = num_classes
self.backbone = backbone
self.dropout_rate = dropout_rate

def get_config(self):
config = super().get_config()
config.update(
{
"num_classes": self.num_classes,
"backbone": keras.saving.serialize_keras_object(self.backbone),
"dropout_rate": self.dropout_rate,
}
)
return config
Expand Down
Loading