计算Pythorch模型失败次数的工具。

thop的Python项目详细描述


thop:pytorch操作计数器

如何安装

pip install thop(现在持续集成在Github actions

pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git

如何使用

  • 基本用法

    fromtorchvision.modelsimportresnet50fromthopimportprofilemodel=resnet50()input=torch.randn(1,3,224,224)flops,params=profile(model,inputs=(input,))
  • 定义第三方模块的规则。

    classYourModule(nn.Module):# your definitiondefcount_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})
  • 提高输出可读性

    调用thop.clever_format以提供更好的输出格式。

    fromthopimportclever_formatflops,params=clever_format([flops,params],"%.3f")

最新模型的结果

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


ModelParams(M)MACs(G)
alexnet58.270.72
densenet1217.612.70
densenet16127.357.31
densenet16913.493.20
densenet20119.094.09
resnet1811.151.70
resnet3420.793.43
resnet5024.373.85
resnet10142.497.33
resnet15257.4010.81
ModelParams(M)MACs(G)
squeezenet1_01.190.77
squeezenet1_11.180.33
vgg11126.717.21
vgg11_bn126.717.24
vgg13126.8810.66
vgg13_bn126.8910.70
vgg16131.9514.54
vgg16_bn131.9614.59
vgg19137.0118.41
vgg19_bn137.0218.47