mirror of
https://github.com/aigc3d/LAM_Audio2Expression.git
synced 2026-02-04 17:39:24 +08:00
feat: Initial commit
This commit is contained in:
33
utils/env.py
Normal file
33
utils/env.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
The code is base on https://github.com/Pointcept/Pointcept
|
||||
"""
|
||||
|
||||
import os
|
||||
import random
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.backends.cudnn as cudnn
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def get_random_seed():
|
||||
seed = (
|
||||
os.getpid()
|
||||
+ int(datetime.now().strftime("%S%f"))
|
||||
+ int.from_bytes(os.urandom(2), "big")
|
||||
)
|
||||
return seed
|
||||
|
||||
|
||||
def set_seed(seed=None):
|
||||
if seed is None:
|
||||
seed = get_random_seed()
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch.manual_seed(seed)
|
||||
torch.cuda.manual_seed(seed)
|
||||
torch.cuda.manual_seed_all(seed)
|
||||
cudnn.benchmark = False
|
||||
cudnn.deterministic = True
|
||||
os.environ["PYTHONHASHSEED"] = str(seed)
|
||||
Reference in New Issue
Block a user