-
Notifications
You must be signed in to change notification settings - Fork 330
fix: make dropout rate configurable in SegFormerImageSegmenter #2627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: float. The dropout rate to apply before the | ||
| segmentation head. Defaults to `0.1`. | ||
|
|
||
|
|
||
| Example: | ||
|
|
@@ -121,6 +123,7 @@ def __init__( | |
| backbone, | ||
| num_classes, | ||
| preprocessor=None, | ||
| dropout=0.1, | ||
|
||
| **kwargs, | ||
| ): | ||
| if not isinstance(backbone, keras.layers.Layer) or not isinstance( | ||
|
|
@@ -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) | ||
|
||
| self.output_segmentation_head = keras.layers.Conv2D( | ||
| filters=num_classes, kernel_size=1, strides=1 | ||
| ) | ||
|
|
@@ -162,13 +165,15 @@ def __init__( | |
| # === Config === | ||
| self.num_classes = num_classes | ||
| self.backbone = backbone | ||
| self.dropout_rate = dropout | ||
|
||
|
|
||
| def get_config(self): | ||
| config = super().get_config() | ||
| config.update( | ||
| { | ||
| "num_classes": self.num_classes, | ||
| "backbone": keras.saving.serialize_keras_object(self.backbone), | ||
| "dropout": self.dropout_rate, | ||
|
||
| } | ||
| ) | ||
| return config | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency and clarity, let's rename
dropouttodropout_rate. This makes it explicit that the parameter is a rate, which is a common convention. This also follows the style guide's principle of using standardized argument names. I'll leave suggestions on other lines to propagate this change throughout the class.References