{ "info": { "author": "Ligeng Zhu", "author_email": "lykensyu+github@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3" ], "description": "# THOP: PyTorch-OpCounter\n\n## How to install \n\n`pip install thop` (now continously intergrated on [Github actions](https://github.com/features/actions))\n\nOR\n\n`pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git`\n\n## How to use \n* Basic usage \n ```python\n from torchvision.models import resnet50\n from thop import profile\n model = resnet50()\n input = torch.randn(1, 3, 224, 224)\n macs, params = profile(model, inputs=(input, ))\n ``` \n\n* Define the rule for 3rd party module.\n ```python\n class YourModule(nn.Module):\n # your definition\n def count_your_model(model, x, y):\n # your rule here\n\n input = torch.randn(1, 3, 224, 224)\n macs, params = profile(model, inputs=(input, ), \n custom_ops={YourModule: count_your_model})\n ```\n\n* Improve the output readability\n\n Call `thop.clever_format` to give a better format of the output.\n ```python\n from thop import clever_format\n macs, params = clever_format([flops, params], \"%.3f\")\n ``` \n\n## Results of Recent Models\n\nThe implementation are adapted from `torchvision`. Following results can be obtained using [benchmark/evaluate_famours_models.py](benchmark/evaluate_famous_models.py).\n\n
\n
| \n\nModel | Params(M) | MACs(G)\n---|---|---\nalexnet | 61.10 | 0.77\nvgg11 | 132.86 | 7.74\nvgg11_bn | 132.87 | 7.77\nvgg13 | 133.05 | 11.44\nvgg13_bn | 133.05 | 11.49\nvgg16 | 138.36 | 15.61\nvgg16_bn | 138.37 | 15.66\nvgg19 | 143.67 | 19.77\nvgg19_bn | 143.68 | 19.83\nresnet18 | 11.69 | 1.82\nresnet34 | 21.80 | 3.68\nresnet50 | 25.56 | 4.14\nresnet101 | 44.55 | 7.87\nresnet152 | 60.19 | 11.61\nwide_resnet101_2 | 126.89 | 22.84\nwide_resnet50_2 | 68.88 | 11.46\n\n | \n\n\nModel | Params(M) | MACs(G)\n---|---|---\nresnext50_32x4d | 25.03 | 4.29\nresnext101_32x8d | 88.79 | 16.54\ndensenet121 | 7.98 | 2.90\ndensenet161 | 28.68 | 7.85\ndensenet169 | 14.15 | 3.44\ndensenet201 | 20.01 | 4.39\nsqueezenet1_0 | 1.25 | 0.82\nsqueezenet1_1 | 1.24 | 0.35\nmnasnet0_5 | 2.22 | 0.14\nmnasnet0_75 | 3.17 | 0.24\nmnasnet1_0 | 4.38 | 0.34\nmnasnet1_3 | 6.28 | 0.53\nmobilenet_v2 | 3.50 | 0.33\nshufflenet_v2_x0_5 | 1.37 | 0.05\nshufflenet_v2_x1_0 | 2.28 | 0.15\nshufflenet_v2_x1_5 | 3.50 | 0.31\nshufflenet_v2_x2_0 | 7.39 | 0.60\ninception_v3 | 27.16 | 5.75\n\n | \n