计算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")
最新模型的结果
|
|