A tool to count the FLOPs of PyTorch model.
Project description
THOP: PyTorch-OpCounter
How to install
pip install thop (now continously intergrated on Github actions)
OR
pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git
How to use
-
Basic usage
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 the rule for 3rd party module.
class YourModule(nn.Module): # your definition def count_your_model(model, x, y): # your rule here input = torch.randn(1, 3, 224, 224) macs, params = profile(model, inputs=(input, ), custom_ops={YourModule: count_your_model})
-
Improve the output readability
Call
thop.clever_formatto give a better format of the output.from thop import clever_format macs, params = clever_format([macs, params], "%.3f")
Results of Recent Models
The implementation are adapted from torchvision. Following results can be obtained using benchmark/evaluate_famous_models.py.
|
|
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thop-0.1.1.post2209072238-py3-none-any.whl.
File metadata
- Download URL: thop-0.1.1.post2209072238-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.6.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01473c225231927d2ad718351f78ebf7cffe6af3bed464c4f1ba1ef0f7cdda27
|
|
| MD5 |
269834966ac96990646cb15dac973af7
|
|
| BLAKE2b-256 |
bb0f72beeab4ff5221dc47127c80f8834b4bcd0cb36f6ba91c0b1d04a1233403
|