Skip to content

set_seeds

anomaly_match.utils.set_seeds

Random seed initialization for reproducibility.

set_seeds(seed, deterministic=False)

Sets the seeds for the random number generators in torch, numpy and random.

Parameters:

Name Type Description Default
seed int

seed for the random number generators

required
deterministic bool

if True, sets the cudnn to deterministic mode. Default: False

False
Source code in anomaly_match/utils/set_seeds.py
def set_seeds(seed: int, deterministic: bool = False) -> None:
    """Sets the seeds for the random number generators in torch, numpy and random.

    Args:
        seed: seed for the random number generators
        deterministic: if True, sets the cudnn to deterministic mode. Default: False
    """
    random.seed(seed)
    torch.manual_seed(seed)
    np.random.seed(seed)
    if deterministic:
        cudnn.deterministic = True
        cudnn.benchmark = False
    else:
        cudnn.deterministic = False
        cudnn.benchmark = True