Ultralytics THOP package for fast computation of PyTorch model FLOPs and parameters.
Project description
🚀 THOP: PyTorch-OpCounter
Welcome to the 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.
📄 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:
pip install ultralytics-thop
Alternatively, install the latest version directly from GitHub:
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:
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:
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:
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
.
|
|
💡 Contribute
We welcome community contributions to enhance THOP. Please check our Contributing Guide 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 file.
📮 Contact
For bugs or feature requests, please open an issue on GitHub Issues. Join our community on Discord for discussions and support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ultralytics_thop-2.0.12.tar.gz
.
File metadata
- Download URL: ultralytics_thop-2.0.12.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 335860c10191c5b33970eb1f5eb7e472c197095f3a99cfb54687b395171d642d |
|
MD5 | da7330599c6a6009c1a9d9a6a854dff9 |
|
BLAKE2b-256 | 73459685fce351cf79dfae857b0ca08c18587e82b621cfe702a1558c383a0493 |
Provenance
The following attestation bundles were made for ultralytics_thop-2.0.12.tar.gz
:
Publisher:
publish.yml
on ultralytics/thop
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ultralytics_thop-2.0.12.tar.gz
- Subject digest:
335860c10191c5b33970eb1f5eb7e472c197095f3a99cfb54687b395171d642d
- Sigstore transparency entry: 149745097
- Sigstore integration time:
- Predicate type:
File details
Details for the file ultralytics_thop-2.0.12-py3-none-any.whl
.
File metadata
- Download URL: ultralytics_thop-2.0.12-py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 094e713cb019fee240b381c22a2c1c739ea155d48f8d516275deb10460e9246f |
|
MD5 | af1cacadf405862f70d7b05562937245 |
|
BLAKE2b-256 | c36a6d31e65cf396a04b89f6f94386cbc5e843588dcca1ed0c634f455334b3c0 |
Provenance
The following attestation bundles were made for ultralytics_thop-2.0.12-py3-none-any.whl
:
Publisher:
publish.yml
on ultralytics/thop
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
ultralytics_thop-2.0.12-py3-none-any.whl
- Subject digest:
094e713cb019fee240b381c22a2c1c739ea155d48f8d516275deb10460e9246f
- Sigstore transparency entry: 149745098
- Sigstore integration time:
- Predicate type: