A tool to count the FLOPs of PyTorch model.
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:
from torchvision.models import resnet50
from thop import profile
import torch
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
Hashes for ultralytics_thop-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a991b176353c23dd0a25408f0e0dd06010a051fc54f272771cd69225b93aa4cf |
|
MD5 | 6c10354270a9f20e5bc05ab72ba48e97 |
|
BLAKE2b-256 | 26b31366a17fe3b2ccc79711d78ef57de2f42639cfb74d168ebadd45460eb8ca |