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-1908061501.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for thop-0.0.30.post1908061501-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebde24cfa5a15a9e85a6b186bae96be7891a5069ac7965cd0bfd0d2daebcd361 |
|
MD5 | e1e86ced0975eb12501b7e096bba7bac |
|
BLAKE2b-256 | da83363d493f3212b8f42b8f52928fba2b65981bad28683ef9666564faaf86f9 |