thop 0.1.1.post2209072238


pip install thop

  Latest version

Released: Sep 07, 2022

Project Links

Meta
Author: Ligeng Zhu

Classifiers

Programming Language
  • Python :: 3

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 here
    
    input = 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.

Model Params(M) MACs(G)
alexnet 61.10 0.77
vgg11 132.86 7.74
vgg11_bn 132.87 7.77
vgg13 133.05 11.44
vgg13_bn 133.05 11.49
vgg16 138.36 15.61
vgg16_bn 138.37 15.66
vgg19 143.67 19.77
vgg19_bn 143.68 19.83
resnet18 11.69 1.82
resnet34 21.80 3.68
resnet50 25.56 4.14
resnet101 44.55 7.87
resnet152 60.19 11.61
wide_resnet101_2 126.89 22.84
wide_resnet50_2 68.88 11.46
Model Params(M) MACs(G)
resnext50_32x4d 25.03 4.29
resnext101_32x8d 88.79 16.54
densenet121 7.98 2.90
densenet161 28.68 7.85
densenet169 14.15 3.44
densenet201 20.01 4.39
squeezenet1_0 1.25 0.82
squeezenet1_1 1.24 0.35
mnasnet0_5 2.22 0.14
mnasnet0_75 3.17 0.24
mnasnet1_0 4.38 0.34
mnasnet1_3 6.28 0.53
mobilenet_v2 3.50 0.33
shufflenet_v2_x0_5 1.37 0.05
shufflenet_v2_x1_0 2.28 0.15
shufflenet_v2_x1_5 3.50 0.31
shufflenet_v2_x2_0 7.39 0.60
inception_v3 27.16 5.75
0.1.1.post2209072238 Sep 07, 2022
0.1.1.post2207130030 Jul 12, 2022
0.1.0.post2207010342 Jun 30, 2022
0.1.0.post2206102148 Jun 10, 2022
0.0.31.post2005241907 May 24, 2020
0.0.31.post2005141830 May 14, 2020
0.0.31.post2005141432 May 14, 2020
0.0.31.post2004101309 Apr 10, 2020
0.0.31.post2004070130 Apr 07, 2020
0.0.31.post2001170342 Jan 17, 2020
0.0.31.post1912272122 Dec 27, 2019
0.0.31.post1910280903 Oct 28, 2019
0.0.31.post1909230639 Sep 23, 2019
0.0.31.post1909021322 Sep 02, 2019
0.0.30.post1908302010 Aug 30, 2019
0.0.30.post1908282117 Aug 28, 2019
0.0.30.post1908282106 Aug 28, 2019
0.0.30.post1908282105 Aug 28, 2019
0.0.30.post1908281655 Aug 28, 2019
0.0.30.post1908061501 Aug 06, 2019
0.0.30.post1908061459 Aug 06, 2019
0.0.30.post190806 Aug 06, 2019
0.0.30 Aug 06, 2019
0.0.23.post1908061459 Aug 06, 2019
0.0.23.post1908021522 Aug 02, 2019
0.0.23.post1908021517 Aug 02, 2019
0.0.23.post1908021457 Aug 02, 2019
0.0.23.post1907171430 Jul 17, 2019
0.0.23.post1907171426 Jul 17, 2019
0.0.23.post1907011323 Jul 01, 2019
0.0.23.post1906241402 Jun 24, 2019
0.0.23.post1906241219 Jun 24, 2019
0.0.23.post1906241153 Jun 24, 2019
0.0.23 Jun 24, 2019
0.0.22.post421392844089 Jun 24, 2019
0.0.22.post1906241147 Jun 24, 2019
0.0.22 Nov 18, 2018
0.0.21 Nov 18, 2018
0.0.5.post2206102148 Jun 10, 2022
0.0.5.post2206100352 Jun 09, 2022
0.0.5.post2110061705 Oct 06, 2021
0.0.4.post2110061704 Oct 06, 2021
0.0.4.post2109101452 Sep 10, 2021
0.0.4.post2109101449 Sep 10, 2021
0.0.4.post2108202217 Aug 20, 2021
0.0.4.post2009191310 Sep 19, 2020
0.0.4.post2009041907 Sep 04, 2020
0.0.4.post2007140009 Jul 14, 2020
0.0.4.post2006111041 Jun 11, 2020
0.0.4.post2006032126 Jun 03, 2020
0.0.2
0.0.1 Nov 18, 2018

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
torch