Skip to content
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

Merged
merged 4 commits into from
Dec 23, 2021
Merged

[Fix] Set random seed for palette if not given. #1152

merged 4 commits into from
Dec 23, 2021

Conversation

jbwang1997
Copy link
Contributor

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

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Dec 19, 2021

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Dec 19, 2021

Codecov Report

Merging #1152 (4377d11) into master (520ec8e) will decrease coverage by 0.03%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
unittests 90.07% <50.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/models/segmentors/base.py 57.85% <0.00%> (-1.48%) ⬇️
mmseg/datasets/custom.py 94.68% <100.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 520ec8e...4377d11. Read the comment docs.

@@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

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.”

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@Junjun2016
Copy link
Collaborator

Hi @jbwang1997
Thanks for your contribution.

@MengzhangLI MengzhangLI changed the title Fix palette in iteration [Fix] Fix palette in iteration. Dec 22, 2021
Copy link
Contributor

@AronLin AronLin left a 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.

@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Prevent loss of randomness.
# It will prevent loss of randomness, as the palette may be different in each iteration if not specified.

Copy link
Contributor Author

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.

Copy link
Collaborator

@Junjun2016 Junjun2016 left a comment

Choose a reason for hiding this comment

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

LGTM

@Junjun2016 Junjun2016 changed the title [Fix] Fix palette in iteration. [Fix] Set random seed for palette if not given. Dec 23, 2021
@Junjun2016 Junjun2016 merged commit 98a353b into open-mmlab:master Dec 23, 2021
bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
…lab#1152)

* Fix colors

* fix comments

* Add comments

* Add comments. Add random seed in datasets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants