主函数
if __name__ == '__main__':
main()
设置当前目录和系统路径
from pathlib import Path
current_dir = Path(__file__).resolve().parent
sys.path.append(str(Path.joinpath(current_dir, "../")))
引入标注功能
from __future__ import annotations
设置随机种子
def seed_everything(seed):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed) # torch随机种子
torch.cuda.manual_seed(seed) # cuda随机种子
torch.backends.cudnn.deterministic = True # cudnn随机种子
torch.backends.cudnn.benchmark = True # cudnn随机种子
# 设置脚本中的随机种子,以便可以进行模型复现
seed_everything(42)
输出模型结构
print("模型的网络结构: {}".format(model))