clinicadl.utils.seed.seed_everything_context¶
- clinicadl.utils.seed.seed_everything_context(seed: int | None = None, deterministic: bool = False) Generator[None, None, None][source]¶
Context manager to control reproducibility.
Does the same as
seed_everything(), but restore all previous random states when exiting the context.- Parameters:
Examples
from clinicadl.utils.seed import seed_everything_context import torch import numpy as np import random
>>> with seed_everything_context(0): print(torch.randn(1), np.random.randn(), random.randint(0, 100)) tensor([1.5410]) 1.764052345967664 49 >>> print(torch.randn(1), np.random.randn(), random.randint(0, 100)) tensor([0.8120]) 0.5023488957207493 50 >>> with seed_everything_context(0): print(torch.randn(1), np.random.randn(), random.randint(0, 100)) tensor([1.5410]) 1.764052345967664 49