pytorch怎么查看参数数量

lewis 2017-05-11 25次阅读

使用pytorch库中的model.parameters()可以获得模型的所有参数,然后使用len()函数可以统计参数的数量。下面是一个示例代码:

import torch
import torch.nn as nn

# 创建模型
model = nn.Linear(10, 5)

# 统计参数数量
num_parameters = sum(p.numel() for p in model.parameters())
print(f"模型参数数量: {num_parameters}")

输出结果会显示模型的参数数量。



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。