Skip to content

Instantly share code, notes, and snippets.

@spider-man-tm
Created December 13, 2021 07:13
Show Gist options
  • Save spider-man-tm/5c628f4de1d2200a69d54babc77da102 to your computer and use it in GitHub Desktop.
Save spider-man-tm/5c628f4de1d2200a69d54babc77da102 to your computer and use it in GitHub Desktop.
- Pythonの各種SEEDを固定 -
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