Skip to content
Open
Changes from 1 commit
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: float. The dropout rate to apply before the
segmentation head. Defaults to `0.1`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and clarity, let's rename dropout to dropout_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.

Suggested change
dropout: float. The dropout rate to apply before the
segmentation head. Defaults to `0.1`.
dropout_rate: float. The dropout rate to apply before the
segmentation head. Defaults to `0.1`.
References
  1. Use standardized names for arg names that should be consistent with other models in the repository. (link)



Example:
Expand Down Expand Up @@ -121,6 +123,7 @@ def __init__(
backbone,
num_classes,
preprocessor=None,
dropout=0.1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As mentioned in the docstring comment, please rename this argument to dropout_rate for consistency.

Suggested change
dropout=0.1,
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Please update this to use the renamed dropout_rate argument.

Suggested change
self.dropout = keras.layers.Dropout(dropout)
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Please update this to use the renamed dropout_rate argument.

Suggested change
self.dropout_rate = dropout
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": self.dropout_rate,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To maintain consistency with the argument and attribute name, the config key should also be dropout_rate.

Suggested change
"dropout": self.dropout_rate,
"dropout_rate": self.dropout_rate,

}
)
return config
Expand Down
Loading