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_format
to 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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file thop-0.0.5.post2206100352-py3-none-any.whl
.
File metadata
- Download URL: thop-0.0.5.post2206100352-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1358a544d3ffc303c89ac2a0244a63627d8d8cc043e7497797ab735d6ab78b12 |
|
MD5 | 980784badecbdca40f71ed0e73ac37e6 |
|
BLAKE2b-256 | 51bb060634e07f32f4d4a8fc44ae06afbdd894bcbacccc732f3dd44696c59452 |