A tool to count the FLOPs of PyTorch model.
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_formatto 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.
|
|
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
Files in release
Extras:
None
Dependencies:
torch