import torch
from yacs.config import CfgNode as CN
# import MODEL
# 加载配置文件 .yaml
path = '' # 配置文件路径
with open(path, 'r') as f:
config = CN.load_cfg(f)
# 创建模型
model = MODEL(config)
total = sum([param.nelement() for param in model.parameters()])
print(f"Number of parameter: {total/1e6:.2f}M")
Pytorch 计算模型的参数量
于 2023-11-15 11:03:54 首次发布