mmdetection icon indicating copy to clipboard operation
mmdetection copied to clipboard

[Fix] Use torch.initial_seed to guarantee the randomness of numpy

Open jbwang1997 opened this issue 2 years ago • 1 comments

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

solve https://github.com/open-mmlab/mmdetection/issues/8110 numpy will be set the same seed in each epoch when pytorch < 1.8

I reproduce the same bug. test code: image the results: image

after modification: image

Modification

Please briefly describe what modification is made in this PR.

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 MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

jbwang1997 avatar Jun 06 '22 09:06 jbwang1997

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (8f3a593) 64.15% compared to head (89f3fb5) 64.17%. Report is 118 commits behind head on dev.

Files Patch % Lines
mmdet/datasets/builder.py 25.00% 3 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8142      +/-   ##
==========================================
+ Coverage   64.15%   64.17%   +0.01%     
==========================================
  Files         361      361              
  Lines       29525    29526       +1     
  Branches     5019     5019              
==========================================
+ Hits        18942    18947       +5     
+ Misses       9578     9576       -2     
+ Partials     1005     1003       -2     
Flag Coverage Δ
unittests 64.14% <25.00%> (+0.01%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 06 '22 10:06 codecov[bot]

Also invite @HAOCHENYE to see if this need to be migrated into MMEngine.

ZwwWayne avatar Oct 08 '22 13:10 ZwwWayne

Also invite @HAOCHENYE to see if this need to be migrated into MMEngine.

Yes, worker_init_fn in MMEngine should also be updated.

BTW, it seems seed is not used here anymore, is this expected?

HAOCHENYE avatar Oct 08 '22 15:10 HAOCHENYE