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.
|
|
Metadata
Release files for thop 0.0.4-2109101452
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| thop-0.0.4.post2109101452-py3-none-any.whl | Python 3 | none | any | Details |
Release files / thop-0.0.4.post2109101452-py3-none-any.whl
| Download URL | thop-0.0.4.post2109101452-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c6525917d3693777dba8c10db5edc5924fed0787bdbb192cb6c202cb1e89c2b
|
|
BLAKE2b-256 checksum How to use checksums |
e700b2781e0a878af107f300b86216766b59329e4b3fe9cb07009d9e9d33acd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|