[pytorch]thop计算模型算力和参数量
创始人
2025-05-29 23:52:46
0

从github官网上转载的:
Count the MACs / FLOPs of your PyTorch model.

THOP: PyTorch-OpCounter

How to install

pip install thop (now continously intergrated on Github actions)

OR

pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git

How to use

  • Basic usage

    from torchvision.models import resnet50
    from thop import profile
    model = resnet50()
    input = torch.randn(1, 3, 224, 224)
    macs, params = profile(model, inputs=(input, ))
    
  • Define the rule for 3rd party module.

    class YourModule(nn.Module):# your definition
    def count_your_model(model, x, y):# your rule hereinput = torch.randn(1, 3, 224, 224)
    macs, params = profile(model, inputs=(input, ), custom_ops={YourModule: count_your_model})
    
  • Improve the output readability

    Call thop.clever_format to give a better format of the output.

    from thop import clever_format
    macs, params = clever_format([macs, params], "%.3f")
    

Results of Recent Models

The implementation are adapted from torchvision. Following results can be obtained using benchmark/evaluate_famous_models.py.

ModelParams(M)MACs(G)
alexnet61.100.77
vgg11132.867.74
vgg11_bn132.877.77
vgg13133.0511.44
vgg13_bn133.0511.49
vgg16138.3615.61
vgg16_bn138.3715.66
vgg19143.6719.77
vgg19_bn143.6819.83
resnet1811.691.82
resnet3421.803.68
resnet5025.564.14
resnet10144.557.87
resnet15260.1911.61
wide_resnet101_2126.8922.84
wide_resnet50_268.8811.46
ModelParams(M)MACs(G)
resnext50_32x4d25.034.29
resnext101_32x8d88.7916.54
densenet1217.982.90
densenet16128.687.85
densenet16914.153.44
densenet20120.014.39
squeezenet1_01.250.82
squeezenet1_11.240.35
mnasnet0_52.220.14
mnasnet0_753.170.24
mnasnet1_04.380.34
mnasnet1_36.280.53
mobilenet_v23.500.33
shufflenet_v2_x0_51.370.05
shufflenet_v2_x1_02.280.15
shufflenet_v2_x1_53.500.31
shufflenet_v2_x2_07.390.60
inception_v327.165.75

相关内容

热门资讯

unity教程||Unity调... 记录下,个人之前做一个项目的时候碰到一个需求,安卓端的app中需要做冷更...
自然语言处理(四): Part... 目录 1. What is Part of Speech (POS)? 词性是什么 2. Infor...
著名央视主持人在甘孜救人,现场... 转自 齐鲁晚报 5月28日 四川甘孜州文广旅局局长刘洪 转发的一条视频 引发关注 视频中,央视主持人...
京郊首个高速停车区主题文化公园... 文、图/赵向红 5月30日,京雄高速(进京方向)房山南停车区内热闹非凡,由“中铁高速”和中国收藏家协...
姑苏首店,玩转假期! 当青石板路遇见首店热潮 当园林雅韵碰撞潮流文化 姑苏区正用首发经济 书写古城商业的破圈秘籍 近期,苏...
缺失的第一个正整数:给定一个未... 给定一个未排序的整数数组,找出其中未出现的最小正整数。 (本文获得CSDN质量评分...
圣祥乳业惊艳第六届北京牛奶文化... 5月29日至31日,由北京市奶业协会主办的第六届北京牛奶文化节在北京中关村移动智能服务创新园(上地・...
原创 拌... #图文打卡计划#大家好呀!今天咱们来聊聊一个让无数厨房新手头疼的问题——为啥自己拌的凉菜总是水汪汪的...
剩米饭大变身!10 分钟做出黄... 家里的剩米饭总在冰箱里 “吃灰”?别浪费!只需 10 分钟,就能将平淡无奇的剩米饭变身金黄酥脆、香气...
原创 空... 端午了,别就知道吃粽子了! 我们吃点新鲜的,艾草戚风蛋糕、奶油粽宝三明治还有脆皮粽子......总有...
如何为孩子挑选健康的零食? 儿童的饮食习惯是他们健康成长的重要基石,然而,如何为孩子挑选健康的零食却让家长感到困惑。根据数据显示...
一口熨斗糕,品尝重庆的童年甜蜜... 在重庆的美食记忆里,熨斗糕宛如一颗甜蜜的糖果,带着童年的纯真与欢乐,让人回味无穷。它那外酥里嫩的口感...
爱情、火锅和踅面 夫妻创业比蜜... 王丽 他生在延安市黄龙县,她诞于韩城市;他总是怀念乡味铜火锅,她一直爱吃家乡的踅面。两人一合计,走!...