具体可以查看 https://github.com/Lyken17/pytorch-OpCounter
THOP: PyTorch-OpCounter
pip install thop
pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git
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})