Name | ultralytics-thop JSON |
Version |
2.0.11
JSON |
| download |
home_page | None |
Summary | Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters. |
upload_time | 2024-11-07 14:35:31 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | AGPL-3.0 |
keywords |
flops
pytorch
model analysis
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<br>
<a href="https://www.ultralytics.com/" target="_blank"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>
# 🚀 THOP: PyTorch-OpCounter
Welcome to the [THOP](https://github.com/ultralytics/thop) repository, your comprehensive solution for profiling PyTorch models by computing the number of Multiply-Accumulate Operations (MACs) and parameters. This tool is essential for deep learning practitioners to evaluate model efficiency and performance.
[![GitHub Actions](https://github.com/ultralytics/thop/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/thop/actions/workflows/main.yml) <a href="https://discord.com/invite/ultralytics"><img alt="Discord" src="https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue"></a> <a href="https://community.ultralytics.com/"><img alt="Ultralytics Forums" src="https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue"></a> <a href="https://reddit.com/r/ultralytics"><img alt="Ultralytics Reddit" src="https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue"></a>
## 📄 Description
THOP offers an intuitive API to profile PyTorch models by calculating the number of MACs and parameters. This functionality is crucial for assessing the computational efficiency and memory footprint of deep learning models.
## 📦 Installation
You can install THOP via pip:
[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-thop?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics-thop/) [![Downloads](https://static.pepy.tech/badge/ultralytics-thop)](https://pepy.tech/project/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)
```bash
pip install ultralytics-thop
```
Alternatively, install the latest version directly from GitHub:
```bash
pip install --upgrade git+https://github.com/ultralytics/thop.git
```
## 🛠How to Use
### Basic Usage
To profile a model, you can use the following example:
```python
import torch
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 Custom Rules for Third-Party Modules
You can define custom rules for unsupported modules:
```python
import torch.nn as nn
class YourModule(nn.Module):
# your definition
pass
def count_your_model(model, x, y):
# your rule here
pass
input = torch.randn(1, 3, 224, 224)
macs, params = profile(model, inputs=(input,), custom_ops={YourModule: count_your_model})
```
### Improve Output Readability
Use `thop.clever_format` for a more readable output:
```python
from thop import clever_format
macs, params = clever_format([macs, params], "%.3f")
```
## 📊 Results of Recent Models
The following table presents the parameters and MACs for popular models. These results can be reproduced using the script `benchmark/evaluate_famous_models.py`.
<table align="center">
<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>
</table>
## 💡 Contribute
We welcome community contributions to enhance THOP. Please check our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for more details. Your feedback and suggestions are highly appreciated!
## 📄 License
THOP is licensed under the AGPL-3.0 License. For more information, see the [LICENSE](https://github.com/ultralytics/thop/blob/main/LICENSE) file.
## 📮 Contact
For bugs or feature requests, please open an issue on [GitHub Issues](https://github.com/ultralytics/thop/pulls). Join our community on [Discord](https://discord.com/invite/ultralytics) for discussions and support.
<br>
<div align="center">
<a href="https://github.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-github.png" width="3%" alt="Ultralytics GitHub"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://www.linkedin.com/company/ultralytics/"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-linkedin.png" width="3%" alt="Ultralytics LinkedIn"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://twitter.com/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-twitter.png" width="3%" alt="Ultralytics Twitter"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://youtube.com/ultralytics?sub_confirmation=1"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-youtube.png" width="3%" alt="Ultralytics YouTube"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://www.tiktok.com/@ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png" width="3%" alt="Ultralytics TikTok"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://ultralytics.com/bilibili"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png" width="3%" alt="Ultralytics BiliBili"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://discord.com/invite/ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png" width="3%" alt="Ultralytics Discord"></a>
</div>
Raw data
{
"_id": null,
"home_page": null,
"name": "ultralytics-thop",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Ultralytics <hello@ultralytics.com>",
"keywords": "FLOPs, PyTorch, Model Analysis",
"author": null,
"author_email": "Ligeng Zhu <ligeng.zhu+github@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/1f/87/372e7a1beea2ed84b05a7b096f86ca67cb9a945337923ca6be6f80d4a200/ultralytics_thop-2.0.11.tar.gz",
"platform": null,
"description": "<br>\n<a href=\"https://www.ultralytics.com/\" target=\"_blank\"><img src=\"https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg\" width=\"320\" alt=\"Ultralytics logo\"></a>\n\n# \ud83d\ude80 THOP: PyTorch-OpCounter\n\nWelcome to the [THOP](https://github.com/ultralytics/thop) repository, your comprehensive solution for profiling PyTorch models by computing the number of Multiply-Accumulate Operations (MACs) and parameters. This tool is essential for deep learning practitioners to evaluate model efficiency and performance.\n\n[![GitHub Actions](https://github.com/ultralytics/thop/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/thop/actions/workflows/main.yml) <a href=\"https://discord.com/invite/ultralytics\"><img alt=\"Discord\" src=\"https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue\"></a> <a href=\"https://community.ultralytics.com/\"><img alt=\"Ultralytics Forums\" src=\"https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue\"></a> <a href=\"https://reddit.com/r/ultralytics\"><img alt=\"Ultralytics Reddit\" src=\"https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue\"></a>\n\n## \ud83d\udcc4 Description\n\nTHOP offers an intuitive API to profile PyTorch models by calculating the number of MACs and parameters. This functionality is crucial for assessing the computational efficiency and memory footprint of deep learning models.\n\n## \ud83d\udce6 Installation\n\nYou can install THOP via pip:\n\n[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-thop?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics-thop/) [![Downloads](https://static.pepy.tech/badge/ultralytics-thop)](https://pepy.tech/project/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)\n\n```bash\npip install ultralytics-thop\n```\n\nAlternatively, install the latest version directly from GitHub:\n\n```bash\npip install --upgrade git+https://github.com/ultralytics/thop.git\n```\n\n## \ud83d\udee0 How to Use\n\n### Basic Usage\n\nTo profile a model, you can use the following example:\n\n```python\nimport torch\nfrom torchvision.models import resnet50\n\nfrom thop import profile\n\nmodel = resnet50()\ninput = torch.randn(1, 3, 224, 224)\nmacs, params = profile(model, inputs=(input,))\n```\n\n### Define Custom Rules for Third-Party Modules\n\nYou can define custom rules for unsupported modules:\n\n```python\nimport torch.nn as nn\n\n\nclass YourModule(nn.Module):\n # your definition\n pass\n\n\ndef count_your_model(model, x, y):\n # your rule here\n pass\n\n\ninput = torch.randn(1, 3, 224, 224)\nmacs, params = profile(model, inputs=(input,), custom_ops={YourModule: count_your_model})\n```\n\n### Improve Output Readability\n\nUse `thop.clever_format` for a more readable output:\n\n```python\nfrom thop import clever_format\n\nmacs, params = clever_format([macs, params], \"%.3f\")\n```\n\n## \ud83d\udcca Results of Recent Models\n\nThe following table presents the parameters and MACs for popular models. These results can be reproduced using the script `benchmark/evaluate_famous_models.py`.\n\n<table align=\"center\">\n<tr>\n<td>\n\n| Model | Params(M) | MACs(G) |\n| ---------------- | --------- | ------- |\n| alexnet | 61.10 | 0.77 |\n| vgg11 | 132.86 | 7.74 |\n| vgg11_bn | 132.87 | 7.77 |\n| vgg13 | 133.05 | 11.44 |\n| vgg13_bn | 133.05 | 11.49 |\n| vgg16 | 138.36 | 15.61 |\n| vgg16_bn | 138.37 | 15.66 |\n| vgg19 | 143.67 | 19.77 |\n| vgg19_bn | 143.68 | 19.83 |\n| resnet18 | 11.69 | 1.82 |\n| resnet34 | 21.80 | 3.68 |\n| resnet50 | 25.56 | 4.14 |\n| resnet101 | 44.55 | 7.87 |\n| resnet152 | 60.19 | 11.61 |\n| wide_resnet101_2 | 126.89 | 22.84 |\n| wide_resnet50_2 | 68.88 | 11.46 |\n\n</td>\n<td>\n\n| Model | Params(M) | MACs(G) |\n| ------------------ | --------- | ------- |\n| resnext50_32x4d | 25.03 | 4.29 |\n| resnext101_32x8d | 88.79 | 16.54 |\n| densenet121 | 7.98 | 2.90 |\n| densenet161 | 28.68 | 7.85 |\n| densenet169 | 14.15 | 3.44 |\n| densenet201 | 20.01 | 4.39 |\n| squeezenet1_0 | 1.25 | 0.82 |\n| squeezenet1_1 | 1.24 | 0.35 |\n| mnasnet0_5 | 2.22 | 0.14 |\n| mnasnet0_75 | 3.17 | 0.24 |\n| mnasnet1_0 | 4.38 | 0.34 |\n| mnasnet1_3 | 6.28 | 0.53 |\n| mobilenet_v2 | 3.50 | 0.33 |\n| shufflenet_v2_x0_5 | 1.37 | 0.05 |\n| shufflenet_v2_x1_0 | 2.28 | 0.15 |\n| shufflenet_v2_x1_5 | 3.50 | 0.31 |\n| shufflenet_v2_x2_0 | 7.39 | 0.60 |\n| inception_v3 | 27.16 | 5.75 |\n\n</td>\n</tr>\n</table>\n\n## \ud83d\udca1 Contribute\n\nWe welcome community contributions to enhance THOP. Please check our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for more details. Your feedback and suggestions are highly appreciated!\n\n## \ud83d\udcc4 License\n\nTHOP is licensed under the AGPL-3.0 License. For more information, see the [LICENSE](https://github.com/ultralytics/thop/blob/main/LICENSE) file.\n\n## \ud83d\udcee Contact\n\nFor bugs or feature requests, please open an issue on [GitHub Issues](https://github.com/ultralytics/thop/pulls). Join our community on [Discord](https://discord.com/invite/ultralytics) for discussions and support.\n\n<br>\n<div align=\"center\">\n <a href=\"https://github.com/ultralytics\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-github.png\" width=\"3%\" alt=\"Ultralytics GitHub\"></a>\n <img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\">\n <a href=\"https://www.linkedin.com/company/ultralytics/\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-linkedin.png\" width=\"3%\" alt=\"Ultralytics LinkedIn\"></a>\n <img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\">\n <a href=\"https://twitter.com/ultralytics\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-twitter.png\" width=\"3%\" alt=\"Ultralytics Twitter\"></a>\n <img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\">\n <a href=\"https://youtube.com/ultralytics?sub_confirmation=1\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-youtube.png\" width=\"3%\" alt=\"Ultralytics YouTube\"></a>\n <img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\">\n <a href=\"https://www.tiktok.com/@ultralytics\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png\" width=\"3%\" alt=\"Ultralytics TikTok\"></a>\n <img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\">\n <a href=\"https://ultralytics.com/bilibili\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png\" width=\"3%\" alt=\"Ultralytics BiliBili\"></a>\n <img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\">\n <a href=\"https://discord.com/invite/ultralytics\"><img src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png\" width=\"3%\" alt=\"Ultralytics Discord\"></a>\n</div>\n",
"bugtrack_url": null,
"license": "AGPL-3.0",
"summary": "Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.",
"version": "2.0.11",
"project_urls": {
"Bug Reports": "https://github.com/ultralytics/thop/issues",
"Changelog": "https://github.com/ultralytics/thop/releases",
"Documentation": "https://docs.ultralytics.com",
"Homepage": "https://ultralytics.com",
"Source": "https://github.com/ultralytics/thop"
},
"split_keywords": [
"flops",
" pytorch",
" model analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d7ec3650362c6cd72f0a2a9d840cbe7a136ceea6e06b02bb7088a4f436accc5c",
"md5": "5cce9c2143dc0850cb998cf2d5dc5c8a",
"sha256": "49da8b32362a3c3d95cbb89d49311c5ab7f1e5af96a27ded6212a62b2db8549f"
},
"downloads": -1,
"filename": "ultralytics_thop-2.0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5cce9c2143dc0850cb998cf2d5dc5c8a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 26080,
"upload_time": "2024-11-07T14:35:28",
"upload_time_iso_8601": "2024-11-07T14:35:28.979692Z",
"url": "https://files.pythonhosted.org/packages/d7/ec/3650362c6cd72f0a2a9d840cbe7a136ceea6e06b02bb7088a4f436accc5c/ultralytics_thop-2.0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1f87372e7a1beea2ed84b05a7b096f86ca67cb9a945337923ca6be6f80d4a200",
"md5": "d3e7e7f77eae1aab11d7ff192c187875",
"sha256": "1be3b6176231479d478b4591ee098368ee04249013123ef9cbd043b9d3a15ddd"
},
"downloads": -1,
"filename": "ultralytics_thop-2.0.11.tar.gz",
"has_sig": false,
"md5_digest": "d3e7e7f77eae1aab11d7ff192c187875",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 28765,
"upload_time": "2024-11-07T14:35:31",
"upload_time_iso_8601": "2024-11-07T14:35:31.057892Z",
"url": "https://files.pythonhosted.org/packages/1f/87/372e7a1beea2ed84b05a7b096f86ca67cb9a945337923ca6be6f80d4a200/ultralytics_thop-2.0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-07 14:35:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ultralytics",
"github_project": "thop",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ultralytics-thop"
}