Skip to main content

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

Model Params(M) FLOPs(G)
alexnet 58.27 0.77
densenet121 7.61 2.71
densenet161 27.35 7.34
densenet169 13.49 3.22
densenet201 19.09 4.11
resnet101 42.49 7.34
resnet152 57.40 10.82
resnet18 11.15 1.70
resnet34 20.79 3.43
resnet50 24.37 3.86
Model Params(M) FLOPs(G)
squeezenet1_0 1.19 1.01
squeezenet1_1 1.18 0.48
vgg11 126.71 7.98
vgg11_bn 126.71 8.01
vgg13 126.88 11.82
vgg13_bn 126.89 11.86
vgg16 131.95 16.12
vgg16_bn 131.96 16.17
vgg19 137.01 20.43
vgg19_bn 137.02 20.49

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.23-1908021517.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thop-0.0.23.post1908021517-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file thop-0.0.23-1908021517.tar.gz.

File metadata

  • Download URL: thop-0.0.23-1908021517.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for thop-0.0.23-1908021517.tar.gz
Algorithm Hash digest
SHA256 4ee84c5f20fd07c556ea1141b1883770a2f50d70a2cb5e70b62a70fbcbe6101c
MD5 fccce402c8281ceb39f98e8fd8eb9a19
BLAKE2b-256 f1faa21a7a1b7fae20753bba7db45069b705e1c908ad8c0271c31502ccffe36c

See more details on using hashes here.

File details

Details for the file thop-0.0.23.post1908021517-py3-none-any.whl.

File metadata

  • Download URL: thop-0.0.23.post1908021517-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for thop-0.0.23.post1908021517-py3-none-any.whl
Algorithm Hash digest
SHA256 9dc4ff119db9d755479a0217f6291c7ad47055a4bc285d89e03efff62fc17727
MD5 5b61a678683100f3408d6bfc67fd9ac8
BLAKE2b-256 079923d498d09991eb7977faf1dd9c2c6982e7e0d456132d0f4c7f84ab0c803e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page