[Docs] Add docs about how to set the random seed (#386)

* how to set seed

* minor fix
pull/391/head
Range King 2022-12-19 14:17:44 +08:00 committed by GitHub
parent 051d30a41a
commit d03dc0bfb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -463,3 +463,22 @@ mim run mmdet print_config \
```
Running the above command will save the `yolov5_s-v61_syncbn_fast_1xb4-300e_balloon.py` config file with the inheritance relationship expanded to \`\`yolov5_s-v61_syncbn_fast_1xb4-300e_balloon_whole.py`in the`./work_dirs\` folder.
## Set the random seed
If you want to set the random seed during training, you can use the following command.
```shell
python ./tools/train.py \
${CONFIG} \ # path of the config file
--cfg-options randomness.seed=2023 \ # set seed to 2023
[randomness.diff_rank_seed=True] \ # set different seeds according to global rank
[randomness.deterministic=True] # set the deterministic option for CUDNN backend
# [] stands for optional parameters, when actually entering the command line, you do not need to enter []
```
`randomness` has three parameters that can be set, with the following meanings.
- `randomness.seed=2023`, set the random seed to 2023.
- `randomness.diff_rank_seed=True`, set different seeds according to global rank. Defaults to False.
- `randomness.deterministic=True`, set the deterministic option for cuDNN backend, i.e., set `torch.backends.cudnn.deterministic` to True and `torch.backends.cudnn.benchmark` to False. Defaults to False. See https://pytorch.org/docs/stable/notes/randomness.html for more details.

View File

@ -466,3 +466,24 @@ mim run mmdet print_config \
```
运行以上命令,会将 `yolov5_s-v61_syncbn_fast_1xb4-300e_balloon.py` 继承关系展开后的配置文件保存到 `./work_dirs` 文件夹内的 `yolov5_s-v61_syncbn_fast_1xb4-300e_balloon_whole.py` 文件中。
## 设置随机种子
如果想要在训练时指定随机种子,可以使用以下命令:
```shell
python ./tools/train.py \
${CONFIG} \ # 配置文件路径
--cfg-options randomness.seed=2023 \ # 设置随机种子为 2023
[randomness.diff_rank_seed=True] \ # 根据 rank 来设置不同的种子。
[randomness.deterministic=True] # 把 cuDNN 后端确定性选项设置为 True
# [] 代表可选参数,实际输入命令行时,不用输入 []
```
`randomness` 有三个参数可设置,具体含义如下:
- `randomness.seed=2023` ,设置随机种子为 2023。
- `randomness.diff_rank_seed=True`,根据 rank 来设置不同的种子,`diff_rank_seed` 默认为 False。
- `randomness.deterministic=True`,把 cuDNN 后端确定性选项设置为 True即把`torch.backends.cudnn.deterministic` 设为 True`torch.backends.cudnn.benchmark` 设为False。`deterministic` 默认为 False。更多细节见 https://pytorch.org/docs/stable/notes/randomness.html。