禹城网站建设,东莞网站建设做网站,网络规划设计师报名,网站分析总结nelememt()函数Tensor.nelement()-引自Tensor.numel()-引自torch.numel(input)三者的作用是相同的Returns the total number of elements in the inputtensor.返回当前tensor的元素数量利用上面的函数刚好可以统计模型的参数数量parameters()函数Module.parameters(rec…nelememt()函数Tensor.nelement()-引自Tensor.numel()-引自torch.numel(input)三者的作用是相同的Returns the total number of elements in the input tensor.返回当前tensor的元素数量利用上面的函数刚好可以统计模型的参数数量parameters()函数Module.parameters(recurseTrue)Returns an iterator over module parameters.recurse (bool) – if True, then yields parameters of this module and all submodules. Otherwise, yields only parameters that are direct members of this module.返回module的参数迭代器这里的参数parameters其实就是tensor在module中充当参数的作用如果recurse为True返回当前module和子module的参数如果recurse为False只返回当前module的成员参数不返回子module的参数统计module的参数量from torchvision.models import resnet50
model resnet50()
total sum([param.nelement() for param in model.parameters()])
print(total , total)输出total 25557032