from torchvision.models import resnet34
import torch
#需要下面这个头文件
from thop import profile
if __name__ == "__main__":
#模型
model = resnet34()
#初始化输入参数 batchsize channel height width
input = torch.randn(1, 3, 256, 512)
Flops, params = profile(model, inputs=(input,))#inputs根据model的输入来定
print('Flops: % .4fG'%(Flops / 1000000000))# 计算量
print('params参数量: % .4fM'% (params / 1000000)) #参数量:等价与上面的summary输出的Total params值
Pytorch 计算量FLOPs和参数量Parameter的统计
最新推荐文章于 2025-02-27 16:41:53 发布