thop


Namethop JSON
Version 0.1.1.post2209072238 PyPI version JSON
download
home_pagehttps://github.com/Lyken17/pytorch-OpCounter/
SummaryA tool to count the FLOPs of PyTorch model.
upload_time2022-09-07 14:38:37
maintainer
docs_urlNone
authorLigeng Zhu
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # THOP: PyTorch-OpCounter

## How to install 

`pip install thop` (now continously intergrated on [Github actions](https://github.com/features/actions))

OR

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

## How to use 
* Basic usage 
    ```python
    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.
    ```python
    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.
    ```python
    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](benchmark/evaluate_famous_models.py).

<p align="center">
<table>
<tr>
<td>

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

</td>
<td>

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

</td>
</tr>
</p>



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Lyken17/pytorch-OpCounter/",
    "name": "thop",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ligeng Zhu",
    "author_email": "ligeng.zhu+github@gmail.com",
    "download_url": "",
    "platform": null,
    "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([macs, params], \"%.3f\")\n    ```    \n\n## Results of Recent Models\n\nThe implementation are adapted from `torchvision`. Following results can be obtained using [benchmark/evaluate_famous_models.py](benchmark/evaluate_famous_models.py).\n\n<p align=\"center\">\n<table>\n<tr>\n<td>\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</td>\n<td>\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</td>\n</tr>\n</p>\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A tool to count the FLOPs of PyTorch model.",
    "version": "0.1.1.post2209072238",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "269834966ac96990646cb15dac973af7",
                "sha256": "01473c225231927d2ad718351f78ebf7cffe6af3bed464c4f1ba1ef0f7cdda27"
            },
            "downloads": -1,
            "filename": "thop-0.1.1.post2209072238-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "269834966ac96990646cb15dac973af7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15443,
            "upload_time": "2022-09-07T14:38:37",
            "upload_time_iso_8601": "2022-09-07T14:38:37.211729Z",
            "url": "https://files.pythonhosted.org/packages/bb/0f/72beeab4ff5221dc47127c80f8834b4bcd0cb36f6ba91c0b1d04a1233403/thop-0.1.1.post2209072238-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-07 14:38:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Lyken17",
    "github_project": "pytorch-OpCounter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "thop"
}
        
Elapsed time: 0.02461s