https://github.com/Lyken17/pytorch-OpCounter
安装方法很简单:
pip install thop基本用法:
from torchvision.models import resnet50from thop import profilemodel = resnet50()flops, params = profile(model, input_size=(1, 3, 224,224))对自己的module进行特别的计算:
class YourModule(nn.Module):# your definitiondef count_your_model(model, x, y):# your rulehereflops, params = profile(model, input_size=(1, 3, 224,224),custom_ops={YourModule: count_your_model})以上这篇在Pytorch中计算自己模型的FLOPs方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。