ultralytics-thop 2.0.14__py3-none-any.whl → 2.0.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
thop/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- __version__ = "2.0.14"
3
+ __version__ = "2.0.15"
4
4
 
5
5
 
6
6
  import torch
@@ -127,7 +127,8 @@ def count_upsample(m, x, y):
127
127
  "linear",
128
128
  "bilinear",
129
129
  "bicubic",
130
- ): # "trilinear"
130
+ "trilinear",
131
+ ):
131
132
  logging.warning(f"mode {m.mode} is not implemented yet, take it a zero op")
132
133
  m.total_ops += 0
133
134
  else:
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: ultralytics-thop
3
+ Version: 2.0.15
4
+ Summary: Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.
5
+ Author-email: Ligeng Zhu <ligeng.zhu+github@gmail.com>
6
+ Maintainer-email: Ultralytics <hello@ultralytics.com>
7
+ License: AGPL-3.0
8
+ Project-URL: Homepage, https://ultralytics.com
9
+ Project-URL: Source, https://github.com/ultralytics/thop
10
+ Project-URL: Documentation, https://docs.ultralytics.com
11
+ Project-URL: Bug Reports, https://github.com/ultralytics/thop/issues
12
+ Project-URL: Changelog, https://github.com/ultralytics/thop/releases
13
+ Keywords: FLOPs,PyTorch,Model Analysis
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Education
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Topic :: Software Development
27
+ Classifier: Topic :: Scientific/Engineering
28
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
29
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
30
+ Classifier: Operating System :: POSIX :: Linux
31
+ Classifier: Operating System :: MacOS
32
+ Classifier: Operating System :: Microsoft :: Windows
33
+ Requires-Python: >=3.8
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: numpy
37
+ Requires-Dist: torch
38
+ Dynamic: license-file
39
+
40
+ <a href="https://www.ultralytics.com/"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>
41
+
42
+ # 🚀 THOP: PyTorch-OpCounter
43
+
44
+ Welcome to the [THOP](https://github.com/ultralytics/thop) repository, your comprehensive solution for profiling [PyTorch](https://pytorch.org/) models by computing the number of Multiply-Accumulate Operations (MACs) and parameters. Developed by Ultralytics, this tool is essential for [deep learning](https://www.ultralytics.com/glossary/deep-learning-dl) practitioners aiming to evaluate model efficiency and performance, crucial aspects discussed in our [model training tips guide](https://docs.ultralytics.com/guides/model-training-tips/).
45
+
46
+ [![Ultralytics Actions](https://github.com/ultralytics/thop/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/thop/actions/workflows/format.yml)
47
+ [![Ultralytics Discord](https://img.shields.io/discord/1089800235347353640?logo=discord&logoColor=white&label=Discord&color=blue)](https://discord.com/invite/ultralytics)
48
+ [![Ultralytics Forums](https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com&logo=discourse&label=Forums&color=blue)](https://community.ultralytics.com/)
49
+ [![Ultralytics Reddit](https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat&logo=reddit&logoColor=white&label=Reddit&color=blue)](https://reddit.com/r/ultralytics)
50
+
51
+ ## 📄 Description
52
+
53
+ THOP offers an intuitive API designed to profile PyTorch models by calculating the total number of MACs and parameters. This functionality is vital for assessing the computational efficiency and memory footprint of deep learning models, helping developers optimize performance for deployment, especially on [edge devices](https://www.ultralytics.com/glossary/edge-ai). Understanding these metrics is key to selecting the right model architecture, a topic explored in our [model comparison pages](https://docs.ultralytics.com/compare/).
54
+
55
+ ## 📦 Installation
56
+
57
+ Get started with THOP quickly by installing it via pip:
58
+
59
+ [![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://www.pepy.tech/projects/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)
60
+
61
+ ```bash
62
+ pip install ultralytics-thop
63
+ ```
64
+
65
+ Alternatively, for the latest features and updates, install directly from the GitHub repository:
66
+
67
+ ```bash
68
+ pip install --upgrade git+https://github.com/ultralytics/thop.git
69
+ ```
70
+
71
+ This ensures you have the most recent version, incorporating the latest improvements and bug fixes.
72
+
73
+ ## 🛠️ How to Use
74
+
75
+ ### Basic Usage
76
+
77
+ Profiling a standard PyTorch model like [ResNet50](https://pytorch.org/vision/main/models/generated/torchvision.models.resnet50.html) is straightforward. Import the necessary libraries, load your model and a sample input tensor, then use the `profile` function:
78
+
79
+ ```python
80
+ import torch
81
+ from torchvision.models import resnet50 # Example model
82
+
83
+ from thop import profile # Import the profile function from THOP
84
+
85
+ # Load a pre-trained model (e.g., ResNet50)
86
+ model = resnet50()
87
+
88
+ # Create a dummy input tensor matching the model's expected input shape
89
+ dummy_input = torch.randn(1, 3, 224, 224)
90
+
91
+ # Profile the model
92
+ macs, params = profile(model, inputs=(dummy_input,))
93
+
94
+ print(f"MACs: {macs}, Parameters: {params}")
95
+ # Expected output: MACs: 4139975680.0, Parameters: 25557032.0
96
+ ```
97
+
98
+ ### Define Custom Rules for Third-Party Modules
99
+
100
+ If your model includes custom or third-party modules not natively supported by THOP, you can define custom profiling rules using the `custom_ops` argument. This allows for accurate profiling even with complex or non-standard architectures, which is useful when working with models like those found in the [Ultralytics models section](https://docs.ultralytics.com/models/).
101
+
102
+ ```python
103
+ import torch
104
+ import torch.nn as nn
105
+
106
+ from thop import profile
107
+
108
+
109
+ # Define your custom module
110
+ class YourCustomModule(nn.Module):
111
+ def __init__(self):
112
+ super().__init__()
113
+ # Define layers, e.g., a convolution
114
+ self.conv = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1)
115
+
116
+ def forward(self, x):
117
+ return self.conv(x)
118
+
119
+
120
+ # Define a custom counting function for your module
121
+ # This function should calculate and return the MACs for the module's operations
122
+ def count_your_custom_module(module, x, y):
123
+ # Example: Calculate MACs for the conv layer
124
+ # Note: This is a simplified example. Real calculations depend on the module's specifics.
125
+ # MACs = output_height * output_width * kernel_height * kernel_width * in_channels * out_channels
126
+ # For simplicity, we'll just assign a placeholder value or use a helper if available
127
+ # In a real scenario, you'd implement the precise MAC calculation here.
128
+ # For nn.Conv2d, THOP usually handles it, but this demonstrates the concept.
129
+ macs = 0 # Placeholder: Implement actual MAC calculation based on module logic
130
+ # You might need access to module properties like kernel_size, stride, padding, channels etc.
131
+ # Example for a Conv2d layer (simplified):
132
+ if isinstance(module, nn.Conv2d):
133
+ _, _, H, W = y.shape # Output shape
134
+ k_h, k_w = module.kernel_size
135
+ in_c = module.in_channels
136
+ out_c = module.out_channels
137
+ groups = module.groups
138
+ macs = (k_h * k_w * in_c * out_c * H * W) / groups
139
+ module.total_ops += torch.DoubleTensor([macs]) # Accumulate MACs
140
+
141
+
142
+ # Instantiate a model containing your custom module
143
+ model = YourCustomModule() # Or a larger model incorporating this module
144
+
145
+ # Create a dummy input
146
+ dummy_input = torch.randn(1, 3, 224, 224)
147
+
148
+ # Profile the model, providing the custom operation mapping
149
+ macs, params = profile(model, inputs=(dummy_input,), custom_ops={YourCustomModule: count_your_custom_module})
150
+
151
+ print(f"Custom MACs: {macs}, Parameters: {params}")
152
+ # Expected output: Custom MACs: 87457792.0, Parameters: 1792.0
153
+ ```
154
+
155
+ ### Improve Output Readability
156
+
157
+ For clearer and more interpretable results, use the `thop.clever_format` function. This formats the raw MACs and parameter counts into human-readable strings (e.g., GigaMACs, MegaParams). This formatting helps in quickly understanding the scale of computational resources required, similar to the metrics provided in our [Ultralytics YOLOv8 documentation](https://docs.ultralytics.com/models/yolov8/).
158
+
159
+ ```python
160
+ import torch
161
+ from torchvision.models import resnet50
162
+
163
+ from thop import clever_format, profile
164
+
165
+ model = resnet50()
166
+ dummy_input = torch.randn(1, 3, 224, 224)
167
+ macs, params = profile(model, inputs=(dummy_input,))
168
+
169
+ # Format the numbers into a readable format (e.g., 4.14 GMac, 25.56 MParams)
170
+ macs_readable, params_readable = clever_format([macs, params], "%.3f")
171
+
172
+ print(f"Formatted MACs: {macs_readable}, Formatted Parameters: {params_readable}")
173
+ # Expected output: Formatted MACs: 4.140G, Formatted Parameters: 25.557M
174
+ ```
175
+
176
+ ## 📊 Results of Recent Models
177
+
178
+ The table below showcases the parameters and MACs for several popular [computer vision](https://www.ultralytics.com/glossary/computer-vision-cv) models, profiled using THOP. These benchmarks provide a comparative overview of model complexity and computational cost. You can reproduce these results by running the script located at `benchmark/evaluate_famous_models.py` in this repository. Comparing these metrics is essential for tasks like selecting models for [object detection](https://www.ultralytics.com/glossary/object-detection) or [image classification](https://www.ultralytics.com/glossary/image-classification). For more comparisons, see our [model comparison section](https://docs.ultralytics.com/compare/).
179
+
180
+ <table align="center">
181
+ <tr>
182
+ <td>
183
+
184
+ | Model | Params(M) | MACs(G) |
185
+ | ---------------- | --------- | ------- |
186
+ | alexnet | 61.10 | 0.77 |
187
+ | vgg11 | 132.86 | 7.74 |
188
+ | vgg11_bn | 132.87 | 7.77 |
189
+ | vgg13 | 133.05 | 11.44 |
190
+ | vgg13_bn | 133.05 | 11.49 |
191
+ | vgg16 | 138.36 | 15.61 |
192
+ | vgg16_bn | 138.37 | 15.66 |
193
+ | vgg19 | 143.67 | 19.77 |
194
+ | vgg19_bn | 143.68 | 19.83 |
195
+ | resnet18 | 11.69 | 1.82 |
196
+ | resnet34 | 21.80 | 3.68 |
197
+ | resnet50 | 25.56 | 4.14 |
198
+ | resnet101 | 44.55 | 7.87 |
199
+ | resnet152 | 60.19 | 11.61 |
200
+ | wide_resnet101_2 | 126.89 | 22.84 |
201
+ | wide_resnet50_2 | 68.88 | 11.46 |
202
+
203
+ </td>
204
+ <td>
205
+
206
+ | Model | Params(M) | MACs(G) |
207
+ | ------------------ | --------- | ------- |
208
+ | resnext50_32x4d | 25.03 | 4.29 |
209
+ | resnext101_32x8d | 88.79 | 16.54 |
210
+ | densenet121 | 7.98 | 2.90 |
211
+ | densenet161 | 28.68 | 7.85 |
212
+ | densenet169 | 14.15 | 3.44 |
213
+ | densenet201 | 20.01 | 4.39 |
214
+ | squeezenet1_0 | 1.25 | 0.82 |
215
+ | squeezenet1_1 | 1.24 | 0.35 |
216
+ | mnasnet0_5 | 2.22 | 0.14 |
217
+ | mnasnet0_75 | 3.17 | 0.24 |
218
+ | mnasnet1_0 | 4.38 | 0.34 |
219
+ | mnasnet1_3 | 6.28 | 0.53 |
220
+ | mobilenet_v2 | 3.50 | 0.33 |
221
+ | shufflenet_v2_x0_5 | 1.37 | 0.05 |
222
+ | shufflenet_v2_x1_0 | 2.28 | 0.15 |
223
+ | shufflenet_v2_x1_5 | 3.50 | 0.31 |
224
+ | shufflenet_v2_x2_0 | 7.39 | 0.60 |
225
+ | inception_v3 | 27.16 | 5.75 |
226
+
227
+ </td>
228
+ </tr>
229
+ </table>
230
+
231
+ ## 🙌 Contribute
232
+
233
+ We actively welcome and encourage community contributions to make THOP even better! Whether it's adding support for new [PyTorch layers](https://pytorch.org/docs/stable/nn.html), improving existing calculations, enhancing documentation, or fixing bugs, your input is valuable. Please see our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for detailed instructions on how to participate. Together, we can ensure THOP remains a state-of-the-art tool for the [machine learning](https://www.ultralytics.com/glossary/machine-learning-ml) community. Don't hesitate to share your feedback and suggestions!
234
+
235
+ ## 📜 License
236
+
237
+ THOP is distributed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.en.html). This license promotes open collaboration and sharing of improvements. For complete details, please refer to the [LICENSE](https://github.com/ultralytics/thop/blob/main/LICENSE) file included in the repository. Understanding the license is important before integrating THOP into your projects, especially for commercial applications which may require an [Enterprise License](https://www.ultralytics.com/license).
238
+
239
+ ## 📧 Contact
240
+
241
+ Encountered a bug or have a feature request? Please submit an issue through our [GitHub Issues](https://github.com/ultralytics/thop/issues) page. For general discussions, questions, and community support, join the vibrant Ultralytics community on our [Discord server](https://discord.com/invite/ultralytics). We look forward to hearing from you and collaborating!
242
+
243
+ <br>
244
+ <div align="center">
245
+ <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>
246
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
247
+ <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>
248
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
249
+ <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>
250
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
251
+ <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>
252
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
253
+ <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>
254
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
255
+ <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>
256
+ <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
257
+ <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>
258
+ </div>
@@ -0,0 +1,13 @@
1
+ thop/__init__.py,sha256=mEWL6Ykse9frz8z9HIb5QWmXY9QpDL41UP2yStOsVaM,219
2
+ thop/fx_profile.py,sha256=ACI2RLyDYBLB7Cru9y2IAx_YCFX_uhYEArDR0np_tFc,8231
3
+ thop/profile.py,sha256=VaCR0K2oWTHp0y-W3SbuA4TdnyxTP6n6VSURltJGzrE,7980
4
+ thop/rnn_hooks.py,sha256=JKZ2eSCvIKvhvCDqM4oWPZjmBkdyJ4R2Q7XSn63lsX0,6503
5
+ thop/utils.py,sha256=IwFJQ1v-SLyhm-313Li535R6fhtomkm8Fem1Kfe6G_U,1484
6
+ thop/vision/__init__.py,sha256=lm6MckFYCPTbqIoX7w0s_daxdjNeBeKW6DXppv1-QUM,70
7
+ thop/vision/basic_hooks.py,sha256=UKMHbH-dP2wx0LCaWVMHtS9o5hJsClmFQrJrPFm0uxY,4714
8
+ thop/vision/calc_func.py,sha256=s-_tRmimNBl4PYY_WQHb3C1H4nLy-oEW2kvsZDVjvdI,4362
9
+ ultralytics_thop-2.0.15.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
10
+ ultralytics_thop-2.0.15.dist-info/METADATA,sha256=8pRLCm325cTHHSpygLu0DlmP8XR9rQR-qwytLJ4PYTw,14922
11
+ ultralytics_thop-2.0.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ ultralytics_thop-2.0.15.dist-info/top_level.txt,sha256=HQ7D0gSvDJ31CNR-f0EuXNVve05RYBmwyIkHQKiEhU8,5
13
+ ultralytics_thop-2.0.15.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,199 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: ultralytics-thop
3
- Version: 2.0.14
4
- Summary: Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.
5
- Author-email: Ligeng Zhu <ligeng.zhu+github@gmail.com>
6
- Maintainer-email: Ultralytics <hello@ultralytics.com>
7
- License: AGPL-3.0
8
- Project-URL: Homepage, https://ultralytics.com
9
- Project-URL: Source, https://github.com/ultralytics/thop
10
- Project-URL: Documentation, https://docs.ultralytics.com
11
- Project-URL: Bug Reports, https://github.com/ultralytics/thop/issues
12
- Project-URL: Changelog, https://github.com/ultralytics/thop/releases
13
- Keywords: FLOPs,PyTorch,Model Analysis
14
- Classifier: Development Status :: 4 - Beta
15
- Classifier: Intended Audience :: Developers
16
- Classifier: Intended Audience :: Education
17
- Classifier: Intended Audience :: Science/Research
18
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
19
- Classifier: Programming Language :: Python :: 3
20
- Classifier: Programming Language :: Python :: 3.8
21
- Classifier: Programming Language :: Python :: 3.9
22
- Classifier: Programming Language :: Python :: 3.10
23
- Classifier: Programming Language :: Python :: 3.11
24
- Classifier: Programming Language :: Python :: 3.12
25
- Classifier: Programming Language :: Python :: 3.13
26
- Classifier: Topic :: Software Development
27
- Classifier: Topic :: Scientific/Engineering
28
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
29
- Classifier: Topic :: Scientific/Engineering :: Image Recognition
30
- Classifier: Operating System :: POSIX :: Linux
31
- Classifier: Operating System :: MacOS
32
- Classifier: Operating System :: Microsoft :: Windows
33
- Requires-Python: >=3.8
34
- Description-Content-Type: text/markdown
35
- License-File: LICENSE
36
- Requires-Dist: numpy
37
- Requires-Dist: torch
38
-
39
- <br>
40
- <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>
41
-
42
- # 🚀 THOP: PyTorch-OpCounter
43
-
44
- 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.
45
-
46
- [![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>
47
-
48
- ## 📄 Description
49
-
50
- 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.
51
-
52
- ## 📦 Installation
53
-
54
- You can install THOP via pip:
55
-
56
- [![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://www.pepy.tech/projects/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)
57
-
58
- ```bash
59
- pip install ultralytics-thop
60
- ```
61
-
62
- Alternatively, install the latest version directly from GitHub:
63
-
64
- ```bash
65
- pip install --upgrade git+https://github.com/ultralytics/thop.git
66
- ```
67
-
68
- ## 🛠 How to Use
69
-
70
- ### Basic Usage
71
-
72
- To profile a model, you can use the following example:
73
-
74
- ```python
75
- import torch
76
- from torchvision.models import resnet50
77
-
78
- from thop import profile
79
-
80
- model = resnet50()
81
- input = torch.randn(1, 3, 224, 224)
82
- macs, params = profile(model, inputs=(input,))
83
- ```
84
-
85
- ### Define Custom Rules for Third-Party Modules
86
-
87
- You can define custom rules for unsupported modules:
88
-
89
- ```python
90
- import torch.nn as nn
91
-
92
-
93
- class YourModule(nn.Module):
94
- # your definition
95
- pass
96
-
97
-
98
- def count_your_model(model, x, y):
99
- # your rule here
100
- pass
101
-
102
-
103
- input = torch.randn(1, 3, 224, 224)
104
- macs, params = profile(model, inputs=(input,), custom_ops={YourModule: count_your_model})
105
- ```
106
-
107
- ### Improve Output Readability
108
-
109
- Use `thop.clever_format` for a more readable output:
110
-
111
- ```python
112
- from thop import clever_format
113
-
114
- macs, params = clever_format([macs, params], "%.3f")
115
- ```
116
-
117
- ## 📊 Results of Recent Models
118
-
119
- The following table presents the parameters and MACs for popular models. These results can be reproduced using the script `benchmark/evaluate_famous_models.py`.
120
-
121
- <table align="center">
122
- <tr>
123
- <td>
124
-
125
- | Model | Params(M) | MACs(G) |
126
- | ---------------- | --------- | ------- |
127
- | alexnet | 61.10 | 0.77 |
128
- | vgg11 | 132.86 | 7.74 |
129
- | vgg11_bn | 132.87 | 7.77 |
130
- | vgg13 | 133.05 | 11.44 |
131
- | vgg13_bn | 133.05 | 11.49 |
132
- | vgg16 | 138.36 | 15.61 |
133
- | vgg16_bn | 138.37 | 15.66 |
134
- | vgg19 | 143.67 | 19.77 |
135
- | vgg19_bn | 143.68 | 19.83 |
136
- | resnet18 | 11.69 | 1.82 |
137
- | resnet34 | 21.80 | 3.68 |
138
- | resnet50 | 25.56 | 4.14 |
139
- | resnet101 | 44.55 | 7.87 |
140
- | resnet152 | 60.19 | 11.61 |
141
- | wide_resnet101_2 | 126.89 | 22.84 |
142
- | wide_resnet50_2 | 68.88 | 11.46 |
143
-
144
- </td>
145
- <td>
146
-
147
- | Model | Params(M) | MACs(G) |
148
- | ------------------ | --------- | ------- |
149
- | resnext50_32x4d | 25.03 | 4.29 |
150
- | resnext101_32x8d | 88.79 | 16.54 |
151
- | densenet121 | 7.98 | 2.90 |
152
- | densenet161 | 28.68 | 7.85 |
153
- | densenet169 | 14.15 | 3.44 |
154
- | densenet201 | 20.01 | 4.39 |
155
- | squeezenet1_0 | 1.25 | 0.82 |
156
- | squeezenet1_1 | 1.24 | 0.35 |
157
- | mnasnet0_5 | 2.22 | 0.14 |
158
- | mnasnet0_75 | 3.17 | 0.24 |
159
- | mnasnet1_0 | 4.38 | 0.34 |
160
- | mnasnet1_3 | 6.28 | 0.53 |
161
- | mobilenet_v2 | 3.50 | 0.33 |
162
- | shufflenet_v2_x0_5 | 1.37 | 0.05 |
163
- | shufflenet_v2_x1_0 | 2.28 | 0.15 |
164
- | shufflenet_v2_x1_5 | 3.50 | 0.31 |
165
- | shufflenet_v2_x2_0 | 7.39 | 0.60 |
166
- | inception_v3 | 27.16 | 5.75 |
167
-
168
- </td>
169
- </tr>
170
- </table>
171
-
172
- ## 💡 Contribute
173
-
174
- 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!
175
-
176
- ## 📄 License
177
-
178
- THOP is licensed under the AGPL-3.0 License. For more information, see the [LICENSE](https://github.com/ultralytics/thop/blob/main/LICENSE) file.
179
-
180
- ## 📮 Contact
181
-
182
- 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.
183
-
184
- <br>
185
- <div align="center">
186
- <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>
187
- <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
188
- <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>
189
- <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
190
- <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>
191
- <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
192
- <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>
193
- <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
194
- <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>
195
- <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
196
- <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>
197
- <img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
198
- <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>
199
- </div>
@@ -1,13 +0,0 @@
1
- thop/__init__.py,sha256=OSUVoANnWspwoPV8jMIKVV29T_vwfq0SwK-zB63EwMU,219
2
- thop/fx_profile.py,sha256=ACI2RLyDYBLB7Cru9y2IAx_YCFX_uhYEArDR0np_tFc,8231
3
- thop/profile.py,sha256=VaCR0K2oWTHp0y-W3SbuA4TdnyxTP6n6VSURltJGzrE,7980
4
- thop/rnn_hooks.py,sha256=JKZ2eSCvIKvhvCDqM4oWPZjmBkdyJ4R2Q7XSn63lsX0,6503
5
- thop/utils.py,sha256=IwFJQ1v-SLyhm-313Li535R6fhtomkm8Fem1Kfe6G_U,1484
6
- thop/vision/__init__.py,sha256=lm6MckFYCPTbqIoX7w0s_daxdjNeBeKW6DXppv1-QUM,70
7
- thop/vision/basic_hooks.py,sha256=PlhEIJv4I1NOtcK3pomZxbut8oZ-JhHwJ7NtOLO1rbQ,4708
8
- thop/vision/calc_func.py,sha256=s-_tRmimNBl4PYY_WQHb3C1H4nLy-oEW2kvsZDVjvdI,4362
9
- ultralytics_thop-2.0.14.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
10
- ultralytics_thop-2.0.14.dist-info/METADATA,sha256=Kvy_nKqnpl5s7ABwfVTA1SBbeYhovolYQWy3sOlBXr0,9362
11
- ultralytics_thop-2.0.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
12
- ultralytics_thop-2.0.14.dist-info/top_level.txt,sha256=HQ7D0gSvDJ31CNR-f0EuXNVve05RYBmwyIkHQKiEhU8,5
13
- ultralytics_thop-2.0.14.dist-info/RECORD,,