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()
    flops, params = profile(model, input_size=(1, 3, 224,224))
  • Define the rule for 3rd party module.

    class YourModule(nn.Module):
        # your definition
    def count_your_model(model, x, y):
        # your rule here
    flops, params = profile(model, input_size=(1, 3, 224,224), 
                            custom_ops={YourModule: count_your_model})

Results on Recent Models

ModelParams(M)FLOPs(G)
alexnet61.100.71
vgg11132.867.75
vgg11_bn132.877.76
vgg13133.0511.46
vgg13_bn133.0511.48
vgg16138.3615.62
vgg16_bn138.3715.65
vgg19143.6719.79
vgg19_bn143.6819.82
densenet1217.982.79
densenet16128.687.69
densenet16914.153.33
densenet20120.014.28
resnet1811.691.58
resnet3421.803.44
resnet5025.563.53
resnet10144.557.26
resnet15260.1910.99
squeezenet1_01.250.70
squeezenet1_11.240.34

参考:https://github.com/Lyken17/pytorch-OpCounter

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐