Created
December 13, 2021 07:13
-
-
Save spider-man-tm/5c628f4de1d2200a69d54babc77da102 to your computer and use it in GitHub Desktop.
- Pythonの各種SEEDを固定 -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import numpy as np | |
import torch | |
import tensorflow as tf | |
def seed_everything(seed: int) -> None: | |
""" | |
seedの固定 | |
""" | |
np.random.seed(seed) | |
random.seed(seed) | |
os.environ["PYTHONHASHSEED"] = str(seed) | |
tf.random.set_seed(seed) | |
torch.manual_seed(seed) | |
if torch.cuda.is_available(): | |
torch.cuda.manual_seed(seed) | |
torch.cuda.manual_seed_all(seed) | |
torch.backends.cudnn.deterministic = True | |
torch.backends.cudnn.benchmark = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment