-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Fix] Set random seed for palette
if not given.
#1152
[Fix] Set random seed for palette
if not given.
#1152
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1152 +/- ##
==========================================
- Coverage 90.11% 90.07% -0.04%
==========================================
Files 125 125
Lines 7262 7268 +6
Branches 1206 1206
==========================================
+ Hits 6544 6547 +3
- Misses 515 518 +3
Partials 203 203
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@@ -245,8 +245,12 @@ def show_result(self, | |||
seg = result[0] | |||
if palette is None: | |||
if self.PALETTE is None: | |||
# Fix colors by setting random seed. | |||
state = np.random.get_state() |
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.
Can add more comments, refer to https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/visualization/image.py#L94-L96.
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.
Also, add this line in comments “The palette may be different in each iteration if not specified.”
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.
Also, add this line in comments “The palette may be different in each iteration if not specified.”
But if set np.random.seed(42), the random palette will be fixed in each iteration.
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.
Of course. My point is an additional straightforward explanation in comments for this modification.
Hi @jbwang1997 |
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.
https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/datasets/custom.py#L352
Here is another random function, you can modify it at the same time.
mmseg/models/segmentors/base.py
Outdated
@@ -245,8 +245,16 @@ def show_result(self, | |||
seg = result[0] | |||
if palette is None: | |||
if self.PALETTE is None: | |||
# Get random state before set seed, | |||
# and restore random state later. | |||
# Prevent loss of randomness. |
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.
# Prevent loss of randomness. | |
# It will prevent loss of randomness, as the palette may be different in each iteration if not specified. |
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.
OK, I will check it quickly.
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.
LGTM
palette
in iteration.palette
if not given.
…lab#1152) * Fix colors * fix comments * Add comments * Add comments. Add random seed in datasets
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
The palette may be different in each iteration if not specified.
Modification
Add np.random.seed(42) in base.py.
Following the method in mmdet.core.visualization.
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist