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.72
densenet121 7.61 2.70
densenet161 27.35 7.31
densenet169 13.49 3.20
densenet201 19.09 4.09
resnet18 11.15 1.70
resnet34 20.79 3.43
resnet50 24.37 3.85
resnet101 42.49 7.33
resnet152 57.40 10.81
Model Params(M) FLOPs(G)
squeezenet1_0 1.19 0.77
squeezenet1_1 1.18 0.33
vgg11 126.71 7.21
vgg11_bn 126.71 7.24
vgg13 126.88 10.66
vgg13_bn 126.89 10.70
vgg16 131.95 14.54
vgg16_bn 131.96 14.59
vgg19 137.01 18.41
vgg19_bn 137.02 18.47

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-1908061459.tar.gz (4.1 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.30.post1908061459-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file thop-0.0.30-1908061459.tar.gz.

File metadata

  • Download URL: thop-0.0.30-1908061459.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

Hashes for thop-0.0.30-1908061459.tar.gz
Algorithm Hash digest
SHA256 7f36fa90623368e54ee76350708d12159a317411bf839e43acd2ef8242040999
MD5 93504da6cb882441810893f67c9f844b
BLAKE2b-256 1dc04c4ecf671552e9f816795cdfd7d5c7931ec64fd5a409194b561e7a664eea

See more details on using hashes here.

File details

Details for the file thop-0.0.30.post1908061459-py3-none-any.whl.

File metadata

  • Download URL: thop-0.0.30.post1908061459-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

Hashes for thop-0.0.30.post1908061459-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f39f17cf5ce25a865d527144a4cfb8e1314411667e44859285569d52845286
MD5 4211364fd26b40e60c00b88c8299746e
BLAKE2b-256 a3a69f4a0443350aed1a4243cb169eb4fd9ae494008124e5e52a5bc829b06d2b

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