A tool to count the FLOPs of PyTorch model.
Project description
THOP: PyTorch-OpCounter
How to install
-
Through PyPi
pip install thop
-
Using GitHub (always latest)
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) flops, 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) flops, params = profile(model, inputs=(input, ), custom_ops={YourModule: count_your_model})
-
Improve the output readability
Call
thop.clever_format
to give a better format of the output.from thop import clever_format flops, params = clever_format([flops, params], "%.3f")
Results on Recent Models
|
|
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
thop-0.0.30-190806.tar.gz
(4.1 kB
view details)
Built Distribution
File details
Details for the file thop-0.0.30-190806.tar.gz
.
File metadata
- Download URL: thop-0.0.30-190806.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 126df0082e13d21164959e2087ad10f160b076a1654a1c5e6e48979a4c225dd4 |
|
MD5 | f7e6032664e38b90dc6b3d4ffc52f0a7 |
|
BLAKE2b-256 | cbb0dc61f22c849c5fb8a273e26750665d5e1fc02d74b76e5e96c82167c0093f |
File details
Details for the file thop-0.0.30.post190806-py3-none-any.whl
.
File metadata
- Download URL: thop-0.0.30.post190806-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b0f4579ff010cc0b07f175786c993a08aa6073a9874e18ab54df7e424b3d34 |
|
MD5 | 29399d19420c74e614c605210bda4719 |
|
BLAKE2b-256 | 4a0827efe0dee0478e534d993362a764692d71303f91dbb7ac8bdae2652c124c |