资源算法pytorch-OpCounter

pytorch-OpCounter

2019-10-10 | |  152 |   0 |   0

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 resnet50from 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 definitiondef count_your_model(model, x, y):    # your rule hereinput = 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 of Recent Models

The implementation are adapted from torchvision. Following results can be obtained using benchmark/evaluate_famours_models.py.



ModelParams(M)MACs(G)alexnet61.100.77vgg11132.867.74vgg11_bn132.877.77vgg13133.0511.44vgg13_bn133.0511.49vgg16138.3615.61vgg16_bn138.3715.66vgg19143.6719.77vgg19_bn143.6819.83resnet1811.691.82resnet3421.803.68resnet5025.564.14resnet10144.557.87resnet15260.1911.61wide_resnet101_2126.8922.84wide_resnet50_268.8811.46ModelParams(M)MACs(G)resnext50_32x4d25.034.29resnext101_32x8d88.7916.54densenet1217.982.90densenet16128.687.85densenet16914.153.44densenet20120.014.39squeezenet1_01.250.82squeezenet1_11.240.35mnasnet0_52.220.14mnasnet0_753.170.24mnasnet1_04.380.34mnasnet1_36.280.53mobilenet_v23.500.33shufflenet_v2_x0_51.370.05shufflenet_v2_x1_02.280.15shufflenet_v2_x1_53.500.31shufflenet_v2_x2_07.390.60inception_v327.165.75


上一篇:fenchel-young-losses

下一篇:Tor10

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...