ultralytics-thop 2.0.16__tar.gz → 2.0.17__tar.gz

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.
Files changed (22) hide show
  1. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/PKG-INFO +4 -4
  2. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/README.md +3 -3
  3. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/tests/test_matmul.py +1 -1
  4. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/__init__.py +3 -2
  5. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/fx_profile.py +9 -8
  6. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/profile.py +25 -2
  7. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/vision/basic_hooks.py +15 -1
  8. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/ultralytics_thop.egg-info/PKG-INFO +4 -4
  9. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/LICENSE +0 -0
  10. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/pyproject.toml +0 -0
  11. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/setup.cfg +0 -0
  12. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/tests/test_conv2d.py +0 -0
  13. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/tests/test_relu.py +0 -0
  14. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/tests/test_utils.py +0 -0
  15. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/rnn_hooks.py +0 -0
  16. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/utils.py +0 -0
  17. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/vision/__init__.py +0 -0
  18. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/thop/vision/calc_func.py +0 -0
  19. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/ultralytics_thop.egg-info/SOURCES.txt +0 -0
  20. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/ultralytics_thop.egg-info/dependency_links.txt +0 -0
  21. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/ultralytics_thop.egg-info/requires.txt +0 -0
  22. {ultralytics_thop-2.0.16 → ultralytics_thop-2.0.17}/ultralytics_thop.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ultralytics-thop
3
- Version: 2.0.16
3
+ Version: 2.0.17
4
4
  Summary: Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.
5
5
  Author-email: Ligeng Zhu <ligeng.zhu+github@gmail.com>
6
6
  Maintainer-email: Ultralytics <hello@ultralytics.com>
@@ -56,7 +56,7 @@ THOP offers an intuitive API designed to profile PyTorch models by calculating t
56
56
 
57
57
  Get started with THOP quickly by installing it via pip:
58
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/)
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://clickpy.clickhouse.com/dashboard/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)
60
60
 
61
61
  ```bash
62
62
  pip install ultralytics-thop
@@ -74,7 +74,7 @@ This ensures you have the most recent version, incorporating the latest improvem
74
74
 
75
75
  ### Basic Usage
76
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:
77
+ Profiling a standard PyTorch model like [ResNet50](https://docs.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
78
 
79
79
  ```python
80
80
  import torch
@@ -230,7 +230,7 @@ The table below showcases the parameters and MACs for several popular [computer
230
230
 
231
231
  ## 🙌 Contribute
232
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!
233
+ We actively welcome and encourage community contributions to make THOP even better! Whether it's adding support for new [PyTorch layers](https://docs.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
234
 
235
235
  ## 📜 License
236
236
 
@@ -17,7 +17,7 @@ THOP offers an intuitive API designed to profile PyTorch models by calculating t
17
17
 
18
18
  Get started with THOP quickly by installing it via pip:
19
19
 
20
- [![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/)
20
+ [![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://clickpy.clickhouse.com/dashboard/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)
21
21
 
22
22
  ```bash
23
23
  pip install ultralytics-thop
@@ -35,7 +35,7 @@ This ensures you have the most recent version, incorporating the latest improvem
35
35
 
36
36
  ### Basic Usage
37
37
 
38
- 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:
38
+ Profiling a standard PyTorch model like [ResNet50](https://docs.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:
39
39
 
40
40
  ```python
41
41
  import torch
@@ -191,7 +191,7 @@ The table below showcases the parameters and MACs for several popular [computer
191
191
 
192
192
  ## 🙌 Contribute
193
193
 
194
- 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!
194
+ We actively welcome and encourage community contributions to make THOP even better! Whether it's adding support for new [PyTorch layers](https://docs.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!
195
195
 
196
196
  ## 📜 License
197
197
 
@@ -17,7 +17,7 @@ class TestUtils:
17
17
  print(flops, params)
18
18
  assert flops == n * in_c * out_c
19
19
 
20
- def test_matmul_case2(self):
20
+ def test_matmul_case3(self): # Note renamed to case3 by Glenn Jocher as duplicated above function name
21
21
  """Tests matrix multiplication to profile FLOPs and parameters of nn.Linear layer using random dimensions."""
22
22
  for _ in range(10):
23
23
  n, in_c, out_c = torch.randint(1, 500, (3,)).tolist()
@@ -1,7 +1,6 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- __version__ = "2.0.16"
4
-
3
+ __version__ = "2.0.17"
5
4
 
6
5
  import torch
7
6
 
@@ -9,3 +8,5 @@ from .profile import profile, profile_origin
9
8
  from .utils import clever_format
10
9
 
11
10
  default_dtype = torch.float64
11
+
12
+ __all__ = ["profile", "profile_origin", "clever_format", "default_dtype"]
@@ -6,6 +6,11 @@ from distutils.version import LooseVersion
6
6
  import torch
7
7
  import torch as th
8
8
  import torch.nn as nn
9
+ from torch.fx import symbolic_trace
10
+ from torch.fx.passes.shape_prop import ShapeProp
11
+
12
+ from .utils import prRed, prYellow
13
+ from .vision.calc_func import calculate_conv
9
14
 
10
15
  if LooseVersion(torch.__version__) < LooseVersion("1.8.0"):
11
16
  logging.warning(
@@ -40,9 +45,6 @@ def count_fn_linear(input_shapes, output_shapes, *args, **kwargs):
40
45
  return flops
41
46
 
42
47
 
43
- from .vision.calc_func import calculate_conv
44
-
45
-
46
48
  def count_fn_conv2d(input_shapes, output_shapes, *args, **kwargs):
47
49
  """Calculates total operations (FLOPs) for a 2D conv layer based on input and output shapes using
48
50
  `calculate_conv`.
@@ -118,11 +120,6 @@ for k in zero_ops:
118
120
 
119
121
  missing_maps = {}
120
122
 
121
- from torch.fx import symbolic_trace
122
- from torch.fx.passes.shape_prop import ShapeProp
123
-
124
- from .utils import prRed, prYellow
125
-
126
123
 
127
124
  def null_print(*args, **kwargs):
128
125
  """A no-op print function that takes any arguments without performing any actions."""
@@ -211,11 +208,15 @@ def fx_profile(mod: nn.Module, input: th.Tensor, verbose=False):
211
208
  if __name__ == "__main__":
212
209
 
213
210
  class MyOP(nn.Module):
211
+ """Custom operator that performs a simple forward pass dividing input by 1."""
212
+
214
213
  def forward(self, input):
215
214
  """Performs forward pass on given input data."""
216
215
  return input / 1
217
216
 
218
217
  class MyModule(torch.nn.Module):
218
+ """Neural network module with two linear layers and a custom MyOP operator."""
219
+
219
220
  def __init__(self):
220
221
  """Initializes MyModule with two linear layers and a custom MyOP operator."""
221
222
  super().__init__()
@@ -1,7 +1,30 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
 
3
- from thop.rnn_hooks import *
4
- from thop.vision.basic_hooks import *
3
+ from thop.rnn_hooks import (
4
+ count_gru,
5
+ count_gru_cell,
6
+ count_lstm,
7
+ count_lstm_cell,
8
+ count_rnn,
9
+ count_rnn_cell,
10
+ torch,
11
+ )
12
+ from thop.vision.basic_hooks import (
13
+ count_adap_avgpool,
14
+ count_avgpool,
15
+ count_convNd,
16
+ count_convtNd,
17
+ count_linear,
18
+ count_normalization,
19
+ count_parameters,
20
+ count_prelu,
21
+ count_relu,
22
+ count_softmax,
23
+ count_upsample,
24
+ logging,
25
+ nn,
26
+ zero_ops,
27
+ )
5
28
 
6
29
  from .utils import prRed
7
30
 
@@ -2,10 +2,24 @@
2
2
 
3
3
  import logging
4
4
 
5
+ import torch
5
6
  import torch.nn as nn
6
7
  from torch.nn.modules.conv import _ConvNd
7
8
 
8
- from .calc_func import *
9
+ from thop.vision.calc_func import (
10
+ calculate_adaptive_avg,
11
+ calculate_avgpool,
12
+ calculate_conv,
13
+ calculate_conv2d_flops,
14
+ calculate_linear,
15
+ calculate_norm,
16
+ calculate_parameters,
17
+ calculate_relu,
18
+ calculate_relu_flops,
19
+ calculate_softmax,
20
+ calculate_upsample,
21
+ calculate_zero_ops,
22
+ )
9
23
 
10
24
  multiply_adds = 1
11
25
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ultralytics-thop
3
- Version: 2.0.16
3
+ Version: 2.0.17
4
4
  Summary: Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.
5
5
  Author-email: Ligeng Zhu <ligeng.zhu+github@gmail.com>
6
6
  Maintainer-email: Ultralytics <hello@ultralytics.com>
@@ -56,7 +56,7 @@ THOP offers an intuitive API designed to profile PyTorch models by calculating t
56
56
 
57
57
  Get started with THOP quickly by installing it via pip:
58
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/)
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://clickpy.clickhouse.com/dashboard/ultralytics-thop) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-thop?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-thop/)
60
60
 
61
61
  ```bash
62
62
  pip install ultralytics-thop
@@ -74,7 +74,7 @@ This ensures you have the most recent version, incorporating the latest improvem
74
74
 
75
75
  ### Basic Usage
76
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:
77
+ Profiling a standard PyTorch model like [ResNet50](https://docs.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
78
 
79
79
  ```python
80
80
  import torch
@@ -230,7 +230,7 @@ The table below showcases the parameters and MACs for several popular [computer
230
230
 
231
231
  ## 🙌 Contribute
232
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!
233
+ We actively welcome and encourage community contributions to make THOP even better! Whether it's adding support for new [PyTorch layers](https://docs.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
234
 
235
235
  ## 📜 License
236
236