fix: make dropout rate configurable in SegFormerImageSegmenter#2627
fix: make dropout rate configurable in SegFormerImageSegmenter#2627yashwanth510 wants to merge 2 commits intokeras-team:masterfrom
Conversation
The dropout rate was previously hardcoded to 0.1 with no way to configure it or serialize it. This adds a dropout argument to __init__() and includes it in get_config() for proper serialization. Default value is kept at 0.1 to maintain backward compatibility.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the SegFormerImageSegmenter by making its dropout rate configurable. Previously, the dropout rate was fixed at 0.1 and was not properly handled during model serialization, leading to loss of configuration. The changes introduce a dropout parameter to the constructor, ensure this value is used by the dropout layer, and integrate it into the model's configuration for persistent storage and retrieval. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request makes the dropout rate in SegFormerImageSegmenter configurable, which is a good improvement for flexibility and fixing the serialization bug. The implementation is straightforward. I've left a few suggestions to improve naming consistency for the new dropout parameter, which will make the code more aligned with the repository's conventions.
| dropout: float. The dropout rate to apply before the | ||
| segmentation head. Defaults to `0.1`. |
There was a problem hiding this comment.
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.
| 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
- Use standardized names for arg names that should be consistent with other models in the repository. (link)
| backbone, | ||
| num_classes, | ||
| preprocessor=None, | ||
| dropout=0.1, |
| self.backbone = backbone | ||
| self.preprocessor = preprocessor | ||
| self.dropout = keras.layers.Dropout(0.1) | ||
| self.dropout = keras.layers.Dropout(dropout) |
| # === Config === | ||
| self.num_classes = num_classes | ||
| self.backbone = backbone | ||
| self.dropout_rate = dropout |
| { | ||
| "num_classes": self.num_classes, | ||
| "backbone": keras.saving.serialize_keras_object(self.backbone), | ||
| "dropout": self.dropout_rate, |
|
Renamed dropout to dropout_rate throughout for consistency. |
Problem
The
SegFormerImageSegmenterhad its dropout rate stuck at0.1—no way to change it, no way to save or reload that value withget_config(). So, people couldn’t set the dropout rate they wanted, and whatever value was there just disappeared every time they saved or loaded the model.Fix
Now you can set the dropout rate yourself. Here’s what changed:
dropout=0.1parameter to__init__().dropoutargument instead of always using0.1.self.dropout_rateunder the config section."dropout": self.dropout_rateinget_config().The default is still
0.1, so everything works just like before if you don’t set it.cc: @mattdangerw @sachinprasadhs @divyashreepathihalli