当前位置:网站首页>Number of parameters of pytorch statistical model

Number of parameters of pytorch statistical model

2022-06-13 08:53:00 Knife, kesselamo

  • Is to traverse every parameter , Add up the size
import torch

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
paras=torch.load('weights.pth', map_location=device)
count = 0
for k2 in paras:
	l = list(paras[k2].size())
	temporary = 1
	for i in l:
		temporary *= i
	count += temporary
print(count)
原网站

版权声明
本文为[Knife, kesselamo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130851414568.html