|
""" |
|
@Date: 2021/08/15 |
|
@description: |
|
""" |
|
import random |
|
import torch |
|
import torch.backends.cudnn as cudnn |
|
import numpy as np |
|
import os |
|
import cv2 |
|
|
|
|
|
def init_env(seed, deterministic=False, loader_work_num=0): |
|
|
|
|
|
np.random.seed(seed) |
|
random.seed(seed) |
|
os.environ['PYTHONHASHSEED'] = str(seed) |
|
|
|
|
|
torch.manual_seed(seed) |
|
if torch.cuda.is_available(): |
|
torch.cuda.manual_seed(seed) |
|
torch.cuda.manual_seed_all(seed) |
|
|
|
|
|
if deterministic: |
|
|
|
torch.backends.cudnn.benchmark = False |
|
torch.backends.cudnn.deterministic = True |
|
else: |
|
cudnn.benchmark = True |
|
torch.backends.cudnn.deterministic = False |
|
|
|
|
|
if loader_work_num != 0: |
|
cv2.setNumThreads(0) |
|
|